CONCAT PROGRAM IN C++ FOR MCA

SOURCE CODE :

//programed by Paras Wadher
MCA
Nagpur university

//PROGRAM FOR CONCAT In C++

#include<stdio.h>
#include<process.h>
#include<conio.h>
#include<alloc.h>
#define NewNode (Node*)malloc(sizeof(Node))

typedef struct node
{
int item;
struct node *next;
}Node;
Node *Create(Node *);
void concat(Node *, Node *);

void main()
{
Node *start1=NULL,*start2=NULL;
int ch,cnt;
clrscr();
printf(“TO Stop entering data enter -99\n”);
start1=Create(start1);
start2=Create(start2);
concat(start1,start2);
getch();
}
Node *Create(Node *s)
{
Node *tmp=NULL,*t1=NULL;
int num;
t1=s;
do
{
printf(“\nEnter the element\n”);
scanf(“%d”,&num);
if(num!=-99)
{
tmp=NewNode;
tmp->item=num;
tmp->next=NULL;
if(s==NULL)
s=t1=tmp;
else
{
t1->next=tmp;
t1=t1->next;
}
}
else
printf(“Linked list created successfully”);
}while(num!=-99);
return(s);
}
void concat(Node *start1,Node *start2)
{
node *tmp=NULL;
tmp=start1;
while(tmp->next!=NULL)
{
tmp=tmp->next;
}
tmp->next=start2;
while(tmp->next!=NULL)
{
tmp=tmp->next;
}
tmp=start1;
printf(“\n\nConcatnation of two lists\n”);
while(tmp!=NULL)
{
printf(” %d “,tmp->item);
tmp=tmp->next;
}
}
//**************** output ****************************

TO Stop entering data enter -99

Enter the element2

Enter the element4

Enter the element5

Enter the element-99

Linked list created successfully

Enter the element3

Enter the element1

Enter the element7

Enter the element-99
Linked list created successfully
Concatnation of two lists 2 4 5 3 1 7 *//

Leave a Reply

Your email address will not be published. Required fields are marked *