hey, i came across this program linked linear list about nodes and all and i m literaaly flustered @ understanding it(only the code in LLLIST.CPP----i mention below)....specially with the POINTERS...
SO PLZ CAN ANYONE EXPLAIN ME THE WORKING OF THE CODE IN LLLIST.CPP, THAT I HAVE MENTIONED BELOW:icon_cool:....

MAYBE I NEED THE UNDERSTANDING OF POINTERS:icon_lol:

JUST NEED THE UNDERSTANDING OF LLLIST.CPP AND IN THAT JUST NEED THE UNDERSTANDING OF THE WORKING OF ADD FUNCTION AND REST I WILL UNDERSTAND...

//NODE.CPP

#define NULL 0

class Node
{
private:
	int info;
	Node *next;
public:
	Node()
	{
		next=NULL;
	}
	Node(int x)
	{
		info=x;
		next=NULL;
	}
	void setInfo(int info)
	{
		this->info=info;
	}
	int getInfo()
	{
		return info;
	}
	void setNext(Node *next)
	{
		this->next=next;
	}
	Node *getNext()
	{
		return next;
	}
};

////////////////////LLLIST.CPP
class LList
{
private:
	Node *head;
public:
	LList()
	{
		head=NULL;
	}

	void addInfo(int x)
	{
		Node *n = new Node();                  		n->setInfo(x);

		if(head==NULL)
		{
			head=n;
			return;
		}
		Node *c=head;
		while(c->getNext() !=NULL)
			c=c->getNext();
		c->setNext(n);
	}

	int removeFirst()
	{
		if(!isEmpty())
		{
			Node * c=head;
			head=head->getNext();
			int i=c->getInfo();
			delete c;
			return i;
		}
	}
	bool removeInfo(int x)
	{
		if(head==NULL)
			return false;//empty list
		if(head->getInfo()==x)
		{
			head=head->getNext();
		}

		Node *c=head->getNext(), *p=head;
		while((c->getInfo()!=x)&&(c->getNext()!=NULL))
		{
			p=c;
			c=c->getNext();
		}
		if(c->getInfo()==x)
		{
		   p->setNext(c->getNext());
		   delete c;
		   return true;
		}
		else
			return false;
	}

	bool isEmpty()
	{
		if (head==NULL)
			return true;
		else
			return false;
	}
};

////////////////LLMAIN.CPP
#include <iostream>
using namespace std;

void main()
{
	LList l;
	int x;
	char yesno='y';
	while(true)
	{
		cout<<"Want to add info(integer value) to list(y/n) ? ";
		cin>>yesno;
		if((yesno=='y')||(yesno=='Y'))
		{
			cout<<"\n Input info : ";
			cin>>x;
			l.addInfo(x);
		}
		else
			break;
	}

	while(!l.isEmpty())
		cout<<l.removeFirst()<<" ";
}

AGAIN>>>>>>>>>>>JUST NEED THE UNDERSTANDING OF LLLIST.CPP AND IN THAT JUST NEED THE WORKING OF ADD FUNCTION AND REST I WILL UNDERSTAND...

void addInfo(int x)
	{
		Node *n = new Node();                                                        
		n->setInfo(x);

		if(head==NULL)
		{
			head=n;
			return;
		}
		Node *c=head;
		while(c->getNext() !=NULL)           
			c=c->getNext();
		c->setNext(n);
	}

SPECIALLY THIS LOOP....HOW DOES THIS LOOP COMPUTE FORMING A CHAIN OF LINKS

while(c->getNext() !=NULL)           
			c=c->getNext();
Comments
YOUR YELLING MADE MY EYES BLEED - BYE BYE NOW

Don't type in all upper case because it means you are screaming and yelling at us.

You need to understand pointers if you want to understand that program. Here is a good paper on pointers by DaWei

Edited 6 Years Ago by Ancient Dragon: n/a

Don't type in all upper case because it means you are screaming and yelling at us.

You need to understand pointers if you want to understand that program. Here is a good paper on pointers by DaWei

ok.ok..i wont do that.
and yeah thanks for the tit-bit.. an informative piece.:cool:

This article has been dead for over six months. Start a new discussion instead.