New Member FAQ | Forums | Earn Revenue | Posting Guidelines | Help Topics


ResourcesPractice TestsAsk ExpertsQuestion PapersJobsStudy in UKUniversitiesCollegesCoursesSchoolsTraining


My Profile

Awards & Gifts


Active Members
TodayLast 7 Daysmore...





Intersection of two LINK LIST using C


Posted Date:     Total Responses: 0    Posted By: pankaj agarwala   Member Level: Silver   Points/Cash: 4   


C language program used for the intersection two SINGLE LINK LIST



#include
#include
#include


struct node
{
int no;
struct node *next;
};
struct node *start=NULL,*start1=NULL ,*start2=NULL;

void Append(struct node *p)
{
struct node *n;
n=(struct node*)malloc(sizeof(struct node)) ;

printf("\n enter no.");
scanf("%d",&n->no);
n->next=NULL;
if(p==NULL)
{
if(p==start)
start=n;
else
start1=n;
return;
}
while(p->next!=NULL)
{
p=p->next;
}
p->next=n;

}
void AppendInter(struct node*p,int a)
{
struct node *n;
n=(struct node*)malloc(sizeof(struct node));
n->no=a;
n->next=NULL;
if(p==NULL)
{
start2=n;
return;
}

while(p->next!=NULL)
{ if(p->no==a)
return;
p=p->next;

}
if(p->no==a)
return;
p->next=n;

}



void Traverse(struct node *p)
{
if(p==NULL)
{
printf("link list empty");
return;
}
while(p!=NULL)
{
printf("\t %d",p->no);
p=p->next;
}

}

void Intercect()
{
struct node *p,*q;
for(p=start;p!=NULL;p=p->next)
{
for(q=start1;q!=NULL;q=q->next)
{
if(p->no==q->no)
{
AppendInter(start2,q->no);
}
}
}
}



void main()
{
int ch;
clrscr();
do
{
printf("\n\n\n 1 Append in LINKLIST 1");
printf("\n 2 Append in LINKLIST 2");
printf("\n 3 INTERSECT the LINK LIST");
printf("\n 4 TRaverse LINK list 1");
printf("\n 5 Traverse LINK List 2");
printf("\n 6 Traverse LINK list 3");


printf("\n 0 exit");

printf("\nenter your choice");
scanf("%d",&ch);

switch(ch)
{
case 1: Append(start);
break;
case 2: Append(start1);
break;
case 3: Intercect();
break;
case 4: Traverse(start);
break;
case 5: Traverse(start1);
break;
case 6: Traverse(start2);
break;


case 0:

break;
default: printf("\n invalid choice");
}


}while(ch!=0);
getch();
}

Attachments

  • INtersection of two link list (2494-271223-READ.CPP)

  • Project Feedbacks


    No feedbacks found. Be the first to respond...

    Post Feedback
    You must Sign In to post a feedback.
    Next Project: C program to perform different operations on SINGLE LINK LIST
    Previous Project: C program to perform different operation on Double LINK LIST

    Return to Project Index

    Post New Project


    Related Projects

    Subscribe to Email
  • Get Jobs by Email
  • Forum posts by Email
  • Articles by Email



  • website counter

    Online Membersbenson gomez
    Ashish Kumar
    Iti Tyagi
    Sakshi Sood
    Munish kumar
    dks
    Arvind
    siva
    sathishkumar
    Ramakrishna Kambhampati
    More...



    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    AdSense Revenue Sharing sites   Advertise   Talk to Tony John
    ISC Technologies, Kochi - India
    2006 - 2012 All Rights Reserved.