Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct node
- {
- int data;
- node *next;
- };
- void add(node*&head,node*&tail,int item)
- {
- node *newNode=new node;
- newNode->data=item;
- if(head==NULL)
- {
- head=tail=newNode;
- newNode->next=NULL;
- }
- else
- {
- newNode->next=head;
- head=newNode;
- }
- }
- void dis(node *&head)
- {
- node *temp=head;
- if(head==NULL)
- {
- cout<<"Error";
- return;
- }
- else
- while(temp!=NULL)
- {
- cout<<temp->data<<endl;
- temp=temp->next;
- }
- }
- int main()
- {
- node *head,*tail,*head1,*tail1,*head2,*tail2;
- head=tail=head1=tail1=head2=tail2=NULL;
- int i,item;
- for(i=0;i<5;i++)
- {
- cout<<"Enter item ";
- cin>>item;
- add(head,tail,item);
- }
- cout<<"\ncin list 2\n";
- for(i=0;i<5;i++)
- {
- cout<<"Enter item ";
- cin>>item;
- add(head1,tail1,item);
- }
- cout<<"\ncin list 3\n";
- for(i=0;i<5;i++)
- {
- cout<<"Enter item ";
- cin>>item;
- add(head2,tail2,item);
- }
- dis(head);
- dis(head1);
- dis(head2);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment