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...





C program to perform different operation on Double LINK LIST


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


C program to perform Append,Traverse,Search,Update on Double LINK LIST



#include
#include
#include
struct node
{
int no;
struct node *pre,*next;
};
struct node *start=NULL,*last=NULL;


void Append()
{

struct node *n;
n=(struct node*)malloc(sizeof(struct node));
printf("\nEnter no");
scanf("%d",&n->no);
n->next=NULL;
if(start==NULL)
{
start=last=n;
start->pre=NULL;
return;
}
last->next=n;
n->pre=last;
last=n;
}

void ftraverse()
{
struct node *p=start;
if(start==NULL)
{
printf("\n Empty Link List");
return;
}
while(p!=NULL)
{
printf(" %d",p->no);
p=p->next;
}
}

void btraverse()
{
struct node *p=last;
if(last==NULL)
{
printf("\n Empty Link List");
return;
}
while(p!=NULL)
{
printf(" %d",p->no);
p=p->pre;
}
}
void Search(struct node *p)
{
int val;
if(p==NULL)
{
printf("\n Empty Link List");
return;
}
printf("\n Enter element to be SEARched ");
scanf(" %d",&val);
if(p==start)
{
while(p!=NULL)
{
if(val==p->no)
{
printf("\n FOUnd");
return;
}
p=p->next;
}
}
else
{
while(p!=NULL)
{
if(val==p->no)
{
printf("\n FOUNd");
return;
}
p=p->pre;
}

}

printf("\n NOT Found");
}


void Update(struct node *p)
{
int val;
if(p==NULL)
{
printf("\nEmpty LINK lIST");
return;
}
printf("enter element to be UPDated");
scanf("%d",&val);
if(p==start)
{
while(p!=NULL)
{
if(val==p->no)
{
printf("Enter no ");
scanf("%d",&p->no);
printf("\nUpdated");
return;
}
p=p->next;
}
}
else

{
while(p!=NULL)
{
if(val==p->no)
{
printf("\n Enter new no");
scanf("%d",&p->no);
printf("\nUPDated");
return;
}
p=p->next;
}
}
printf("\n %d NOT Found",val);
}




void main()
{
int ch;
clrscr();
do
{
printf("\n 1 Append");
printf("\n 2 Forward TRAverse");
printf("\n 3 BAckward TRAverse");
printf("\n 4 Search from Start");
printf("\n 5 Search from LAST");
printf("\n 6 UPdate from start");
printf("\n 7 Update from LAST");
printf("\n 0 EXIT");
printf("\n Enter your choice");
scanf("%d",&ch);
switch(ch)
{
case 1:Append();
break;
case 2:ftraverse();
break;
case 3:btraverse();
break;
case 4: Search(start);
break;
case 5: Search(last);
break;
case 6: Update(start);
break;
case 7: Update(last);
break;

case 0:
break;

default: printf("\n Invalid Choice");
}
}while(ch!=0);
getch();
}



Attachments

  • Double_LINK_LIST (2499-271420-DDL.CPP)

  • Project Feedbacks


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

    Post Feedback
    You must Sign In to post a feedback.
    Next Project: Intersection of two LINK LIST using C
    Previous Project: C program to perform 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.