Ok, I see.
Well, I am not much into conditional turn based games, but here is an basic approach (pseudocode). : )
It uses lists and queues. Both data structures can be found in my signature.
You can also solve this problem with arrays, though.
/* we start with two lists in which each element stores a pointer to an entity */
new List ListOfHeros
new List ListOfEnemies
/* now we sort those lists descendingly according to the entities agility skills */
list_sort(ListOfHeros, agility)
list_sort(ListOfEnemies, agility)
/* this is our battle queue */
new Queue BattleQueue
/* heros and enemies will be pushed into the battle queue alternately */
while(list_not_empty(ListOfHeros) && list_not_empty(ListOfEnemies))
Cut first element of ListOfHeros
Push it into BattleQueue
Cut first element of ListOfEnemies
Push it into BattleQueue
if (list_not_empty(ListOfHeros))
Push rest of ListOfHeros into BattleQueue
if (list_not_empty(ListOfEnemies))
Push rest of ListOfEnemies into BattleQueue
/* We are done. Now we can pop out the entities one by one. */
entity = queue_pop(BattleQueue) // returns entity with highest agility
...
Hope this helps somehow.