Friday, May 03, 2013

General Linked list character program in C++


#include <iostream>
using namespace std;
struct node{
char data;
node *link;
};
int main(){
node *start,*temp,*prev;
int lim;
cout<<"enter the linked list limited :";
cin>>lim;
start=new node;
prev=start;
cout<<"enter char for location 1 :";
cin>>start->data;
start->link=NULL;
for(int i=2;i<=lim;i++){
temp=new node;
cout<<"enter char for location "<<i<<" : ";
cin>>temp->data;
temp->link=NULL;
prev->link=temp;
prev=temp;                    
}
node* ptr;
ptr=start;
while(ptr!=NULL)
{  cout<<ptr->data<<endl;
      ptr=ptr->link;
}
}


No comments:

Post a Comment