string - C++ Linked List Inserting Char by Char of a word -
i having trouble homework assignment passing object has string inserted linked list of characters (like h-e-l-l-o) , passing list object.
i can first word in list (see function insertword), if want put second word (insert), don't know how to. here code.
i feel it's simple keep missing.
struct character { string symbol; character *next; }; class word { public: word(); word::~word(); void insertword(const string&); void insert(const word&, int slot); void remove(const string&); private: character *front; character *back; int count; }; void word::insertword(const string& key) { int ln = key.length(); (int n = 0; n < ln; n++) { if (front == 0) { front = new character; front->symbol = key[n]; front->next = 0; = front; } else { character *p = new character; p->symbol = key[n]; p->next = front; front = p; } } } void word::insertinto(const word &key, int slot) { if (slot = 0 || 1) { if (front == 0) { front->symbol = key.p; //this lose front->next = 0; = front; } else { p->symbol = key[n]; p->next = front; front = p; } } } int main() { word a; word b; a.insertword("45352"); b.insertword("yzthrh"); a.insertinto(b,1); return 0; }
Comments
Post a Comment