I'm given a task where I should assign a string to a linked list of chars.
My idea to solve this problem is by creating s.length() of nodes, setting their value by a for loop and setting their next to NULL. Then by creating all the nodes, I can proceed to connecting them each other, but the last code
head = NodeArray[0] doesn't work for me. I think I have a misunderstanding somewhere. Suggestions greatly appreciated. Thank you
for class StringADT
for the member functions
My idea to solve this problem is by creating s.length() of nodes, setting their value by a for loop and setting their next to NULL. Then by creating all the nodes, I can proceed to connecting them each other, but the last code
head = NodeArray[0] doesn't work for me. I think I have a misunderstanding somewhere. Suggestions greatly appreciated. Thank you
for class StringADT
class StringADT{ private: struct Node { char data; Node* next; }; Node* head; public: StringADT() { head = NULL; } void append(string); //10 void display() const; //13 ~StringADT(); //3
for the member functions
void StringADT::append(string s) { Node* NodePtr; Node* newNode; int slength = s.length(); Node *NodeArray = new Node[slength]; for (unsigned i = 0; i < s.length(); i++) { NodeArray[i].data = s.at(i); NodeArray[i].next = NULL; } //NOHEAD if (!head) { head = NodeArray[0]; //DOESN'T WORK. } }