Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Linked List of chars from string

$
0
0
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
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.

	}
}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>