All Programs are Written and Compiled in Dev C++. So, it may generate some error in case of other compilers and may need some modifications in program. Download Dev C++

Saturday 15 March 2014

Creating Nodes in Singly Linked List Using Structure.

//Creating Nodes in Singly Linked List Using Structure.
#include<iostream.h>
using namespace std;
struct node
{
 char info;
 node *link;
};
int main()
{
 node *start,*p,*temp;
 start=p=NULL;
 char ch;
 do
 {
  char item;
  cout<<"Input Element to info :";
  cin>>item;
  temp=new node;
  temp->info=item;
  temp->link=NULL;
  if(start==NULL)
start=temp;
  else
p->link=temp;
  p=temp;
  cout<<"Create More Nodes y or n :";
  cin>>ch;
 }while(ch=='y');
 //printing nodes
 p=start;
 while(p)
 {
  cout<<p->info;
  p=p->link;
 }
return 0;
}

No comments:

Post a Comment