Add to Favorites    Make Home Page 5365 Online  
 Language Categories  
 Our Services  

Home » C Home » Beginners / Lab Assignments Home » implementation of circular linked list

A D V E R T I S E M E N T

Search Projects & Source Codes:

Title implementation of circular linked list
Author rahul roy
Author Email doc_rahul127 [at] yahoo.co.in
Description this program is a simple implementation of circular linked list.

Category C » Beginners / Lab Assignments
Hits 398871
Code Select and Copy the Code
#include<stdio.h> #include<conio.h> #include<stdlib.h> typedef struct cllist{ int x; struct cllist *next; }nd; nd*insert(nd**,nd**,nd**); nd*delete(nd**,nd**,nd**); nd*insfro(nd**,nd**,nd**); nd*insaftnd(nd**,nd**,nd**); void display(nd*,nd*); void main() { int n; nd *start,*current,*head; head=(nd*)malloc(sizeof(nd)); start=head; current=start; do{ clrscr(); textbackground(RED); textcolor(BLACK+BLINK); printf(" CIRCULAR LINKED LIST _________________________________________ "); printf(" MAIN MENU ---------------------------- "); printf(" 1>. INSERT 2>.INSERTION AT FRONT 3>.INSERION AFTER A NODE 4>.DELETION 5>.END "); printf(" ______________________________________________________ "); printf(" enter your choice: "); scanf("%d",&n); switch(n) { case 1: insert(&head,&start,¤t); break; case 2: insfro(&head,&start,¤t); break; case 3: insaftnd(&head,&start,¤t); break; case 4: if(start==head){ printf(" the list empty!"); break; } delete(&head,&start,¤t); break; case 5: clrscr(); printf(" "); printf(" press any key to exit..."); getch(); exit(0); default: printf(" invalid choice!"); getch(); break; } }while(n!=5); getch(); } nd*insert(nd**head,nd**start,nd**current) { int m; nd*temp,*val; clrscr(); printf(" INSERTION ______________________________________ n"); do{ temp=(nd*)malloc(sizeof(nd)); if(!temp ){ printf("memory allocation not possible!"); getch(); exit(0); } val=temp; temp=temp->next; printf(" enter the element:"); scanf("%d",&m); val->x=m; val->next=*head; if(*start==*head){ (*head)->next=val; *start=val; *current=*start; } else{ (*current)->next=val; *current=val; } printf(" any more inserton(y/n):"); fflush(stdin); }while(toupper(getch())!='N'); display(*head,*start); getch(); return(*head,*start,*current); } void display(nd*head,nd*start) { if(head==start){ printf(" the list is empty!"); getch(); return; } else{ printf(" the list is now: "); do{ printf("%5d",start->x); start=start->next; }while(start!=head); } return; } nd*delete(nd**head,nd**start,nd**current) { int ele; nd *temp,*save,*val,*pred; clrscr(); printf(" DELETION ___________________________________ " ); save=*start; do{ display(*head,*start ); val=save; printf(" enter the element to be deleted:"); scanf("%d",&ele); while(save->x!=ele && save->next!=val){ pred=save; save=save->next; } if(save->next==val){ printf(" the elment is not in the list!"); getch(); break; } temp=save; printf(" the element to be deleted is:%d",temp->x); printf(" r u sure(y/n):"); fflush(stdin); if(toupper(getch())!='N'){ if(save==(*head)->next){ *start=(*start)->next; free(temp); save=*start; } else if(save->next==*head){ pred->next=*head; *current=pred; free(temp); save=pred; } else{ pred->next=temp->next; free(temp); save=pred; } } else break; printf(" anymore deletion(y/n):"); fflush(stdin); }while(toupper(getch())!='N'); display(*head,*start); getch(); return(*head,*start,*current); } nd*insfro(nd**head,nd**start,nd**current) { int m; nd *temp,*val; clrscr(); printf(" INSERTION IN FRONT "); printf(" __________________________________ "); do{ temp=(nd*)malloc(sizeof(nd)); if(!temp){ printf(" memory allocation not possible!"); getch(); exit(0); } val=temp; temp=temp->next; printf(" enter the element:"); scanf("%d",&m); val->x=m; if(*start==*head){ val->next=*head; (*head)->next=val; *start=val; *current=*start; } else{ (*head)->next=val; val->next=*start; *start=val; } printf(" any more insertion to be performed(y/n):"); fflush(stdin); }while(toupper(getch())!='N'); display(*head,*start); getch(); return(*head,*start,*current); } nd*insaftnd(nd**head,nd**start,nd**current) { int trg,n=1,m; nd *temp,*val,*save,*pred; save=*start; clrscr(); printf(" INSERTION AFTER A NODE "); printf(" __________________________________ "); do{ display(*head,*start); temp=(nd*)malloc(sizeof(nd)); if(!temp){ printf(" memory allocation not possible!"); getch(); exit(0); } val=temp; temp=temp->next; printf(" enter the element:"); scanf("%d",&m); val->x=m; if(*start==*head){ val->next=*head; (*head)->next=val; *start=val; *current=*start; } else{ printf(" enter the position of insertion:"); scanf("%d",&trg); while(trg!=n){ pred=save; save=save->next; n++; if(save==*head) n=0; } pred->next=val; val->next=save; save=save->next; } printf(" any more insertion(y/n):"); fflush(stdin); }while(toupper(getch())!='N'); display(*head,*start); getch(); return(*head,*start,*current); }

Related Source Codes

Script Name Author
The Game Opposite as seen on Nokia 2300 Mobile Manikanta
RECURSIVE BALANCED QUICK SORT ashish
Radix Sort ashish
Change your mouse pointer Ashim
The blinking star Shashank
Data Validation Crylittlebaby
To search a file by giving file type like mp3 or mpeg or doc Prashanth SR
Menus Demonstration B.Chidhambaram
Employee Database Project Using C. Reenku Raman Nayak
Creating a Lexical Analyzer in c fahad bader al-buhairi ¦Õ¤ ?¤Ð Ãß??ÝÐÝ
Calendar Program Omkar & Devendra
Stop double Process for start in C Cedrik Jurak
Stop double Process for start in C Cedrik Jurak
Time Scheduler Atiq Anwar
A timepass game between atmost two players Rahul Roy

A D V E R T I S E M E N T




Google Groups Subscribe to SourceCodesWorld - Techies Talk
Email:

Free eBook - Interview Questions: Get over 1,000 Interview Questions in an eBook for free when you join JobsAssist. Just click on the button below to join JobsAssist and you will immediately receive the Free eBook with thousands of Interview Questions in an ebook when you join.

New! Click here to Add your Code!


ASP Home | C Home | C++ Home | COBOL Home | Java Home | Pascal Home
Source Codes Home Page

 Advertisements  

Google Search

Google

Source Codes World.com is a part of Vyom Network.

Vyom Network : Web Hosting | Dedicated Server | Free SMS, GRE, GMAT, MBA | Online Exams | Freshers Jobs | Software Downloads | Interview Questions | Jobs, Discussions | Placement Papers | Free eBooks | Free eBooks | Free Business Info | Interview Questions | Free Tutorials | Arabic, French, German | IAS Preparation | Jokes, Songs, Fun | Free Classifieds | Free Recipes | Free Downloads | Bangalore Info | Tech Solutions | Project Outsourcing, Web Hosting | GATE Preparation | MBA Preparation | SAP Info | Software Testing | Google Logo Maker | Freshers Jobs

Sitemap | Privacy Policy | Terms and Conditions | Important Websites
Copyright ©2003-2024 SourceCodesWorld.com, All Rights Reserved.
Page URL: http://www.sourcecodesworld.com/source/show.asp?ScriptID=1205


Download Yahoo Messenger | Placement Papers | Free SMS | C Interview Questions | C++ Interview Questions | Quick2Host Review