Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct node_tag
- {
- int Data;
- struct node_tag *link;
- }node;
- node *GetNode()
- {
- node *New;
- New=(node*)malloc(sizeof(node));
- New->link=NULL;
- return New;
- }
- node *InsertAtEnd(node *Last,int x)
- {
- node *New;
- New=GetNode();
- New->Data=x;
- if(Last==NULL)
- {
- Last=New;
- }
- New->link=Last->link;
- Last->link=New;
- Last=New;
- return Last;
- }
- node *Merge(node *Last1,node *Last2)
- {
- node *x;
- x=Last2->link;
- Last2->link=Last1->link;
- Last1->link=x;
- return Last2;
- }
- node *CreateList()
- {
- int ch,x;
- node *Last=NULL;
- while(1)
- {
- printf("enter 0 to stop :");
- scanf("%d",&ch);
- if(ch==0)return Last;
- else
- {
- printf("enter the data :");
- scanf("%d",&x);
- Last=InsertAtEnd(Last,x);
- // Display(Last);
- }
- }
- }
- void Display(node *Last)
- {
- node *x;
- x=Last->link;
- while(x!=Last)
- {
- printf("%d,",x->Data);
- x=x->link;
- }
- printf("%d,",Last->Data);
- }
- int main()
- {
- node *Last1,*Last2,*Last3;
- printf("LIST 1:\n");
- Last1=CreateList();
- printf("\nLIST 1:");
- Display(Last1);
- printf("LIST 2:\n");
- Last2=CreateList();
- printf("\nLIST 2:");
- Display(Last2);
- printf("LIST 3 after Concatinaion:\n");
- Last3=Merge(Last1,Last2);
- printf("\nLIST 3:");
- Display(Last3);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement