Turning an array and a vector into a combined linked list

I am trying to take an array of player mobs and an array of enemy mobs and turn them into a sorted linked list based on a data member within them. However I can't find any tutorials or suggestions on how to do this. All I can find on the internet is how to build a very basic linked list. If anyone could take a look at what I have put together, and offer either suggestions or point me to a tutorial that can tell me how to do this, that would be great. Thanks.
// Declarations //
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class character{
public:
    character();                    // Constructor
    bool operator== (character);    // use when comparing init of objects
    bool operator< (character);
    bool operator> (character);
    string getname ();              // return name of object
    int getinit () ;                // return init of object
    void set_init (int a);          // set init of object to 'a'
    void heal_full();               // max out hp and 0 nl dam
    void heal(int amt);             // modify hp by given amount
    void heal_nl (int amt);         // heal nl dam by given amount
    void dam_nl (int amt);          // give nl dam by given amount, checks for disabled or unconscious state.
    int getHP();                    // return current hp
    int getnlDam();                 // return nl dam
    void SetnMob (character* nmob); // Sets next mob
    character* GetnMob ();          // Gets the address of next mob.

private:
    string name;            // name of character
    int mHP;                // max hit points
    int HP;                 // current hit points
    int nlDam;              // amount of non lethal damage object currently has
    int init;               // initiative of character
    character* nextMob;     // points to next mob to iterate to
};

class encounter{
public:
    encounter (character*, int);        // Constructor
    void listFull ();
private:
    int ENEMIES;                        // number of enemies in this encounter
    vector<character> enemy;            // vector of all enemies in encounter
    vector<character>* holding;
    character* player;
    character* nMob;
};


// Constructor for Encounter // (sets up the linked list for later iteration) sorting is based on init, high to low.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
encounter::encounter (character players_in[], int size ){
    banner ("NEW ENCOUNTER", "*");
    nMob = NULL;
    player = players_in;
    cout << "How many enemies?";
    cin >> ENEMIES;
    for (int i = 0; i < ENEMIES; i++ ){
        enemy.push_back(character () );
    };
    cout << "Roll for initiative and input for each person or enemy:";
    for ( int i = 0; i < size; i++){        // get players init
        int in;
        cout << player[i].getname() << ": ";
        cin >> in;
        player[i].set_init(in);
    };
    for ( int i = 0; i < ENEMIES; i++) {    // get enemies init
        int in;
        cout << enemy[i].getname() << ": ";
        cin >> in;
        enemy[i].set_init(in);
    };
//////////////////////////////
// How should I create and sort the linked list?
// My thought is to sort each array individually and then iterate through both lists
// and combine them. My issue is that I am not sure how to do that.
//////////////////////////////

// sort players by init w/ linked list
    for (int i = 0; i < size; i++) {
        if (player[i].getinit() > high.getinit() ) {
           
        }
        else if (player[i].getinit() == high.getinit() ) {
            
        }
        else if (player[i].getinit() < high.getinit() ) {
            
        }
    }
// sort enemies by init w/ linked list
    for (int i = 0; i < ENEMIES; i++) {
        if (enemy[i].getinit() > high.getinit() ) {
        
        }
        else if (enemy[i].getinit() == high.getinit() ) {
            
        }
        else if (enemy[i].getinit() < high.getinit() ) {

        }
    }
//sort all mobs w/ linked list
    for ( int i = 0, int j =0; i < size && j < ENEMIES ; ) {
        if ( player[i] > enemy[j] ) {
            player[i].SetnMob( enemy[j] );
            i++;
        }
        else if ( player[i] > enemy[j] ) {
            enemy[j].SetnMob( player[i] );
            j++;
        }
        else if ( player[i] == enemy[j] ) {
            bool a = false;
            while (a == false) {
                cout<< player[i].getname() << " and " << enemy[j].getname()
                    << "are tied. Please roll again and select higher init."
                    << "\n1. " << player[i].getname()
                    << "\n2. " << enemy[j].getname();
                int select;
                cin >> select;
                if (select == 1) {
                    player[i].SetnMob( enemy[j] );
                    i++;
                    a = true;
                }
                else if (select == 2) {
                    enemy[j].SetnMob( player[i] );
                    j++;
                    a = true;
                }
                else {
                    cout << "Invalid selection, Please try again";
                }
            }
        }
    }
}
Topic archived. No new replies allowed.