Answer to Question #287146 in C++ for Roe

Question #287146

Provide the pointer-based implementation for singly list



Q->U->E->S->T->I->O->N->S->Null

1
Expert's answer
2022-01-13T03:56:45-0500
#include<iostream>

using namespace std;

struct Node
{
	char ch;
	Node* next;
	Node(char _ch):ch(_ch),next(NULL){}
};

class LinkList
{
	Node* head=NULL;
public:
	void AddNode(char c)
	{
		Node* temp=new Node(c);
		if(head==NULL)
			head=temp;
		else
		{
			Node* p=head;
			while(p->next!=NULL)
			{
				p=p->next;
			}
			p->next=temp;	
		}
	}	
	
	void Display()
	{
		Node* p=head;
		while(p!=NULL)
		{
			cout<<p->ch<<"->";
			p=p->next;
		}	
		cout<<"Null";
	}
};

int main()
{
	LinkList a;
	a.AddNode('Q');
	a.AddNode('U');
	a.AddNode('E');
	a.AddNode('S');
	a.AddNode('T');
	a.AddNode('I');
	a.AddNode('O');
	a.AddNode('N');
	a.AddNode('S');
	a.Display();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment