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

Home » C Home » Data Structures Home » Linked List implementation

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

Search Projects & Source Codes:

Title Linked List implementation
Author Omindra Kumar Rana
Author Email rana_omindra [at] yahoo.co.in
Description Linked List implementation
Category C » Data Structures
Hits 369593
Code Select and Copy the Code
#include"m_list.h" void main() { list *first=NULL,*second=NULL,*third=NULL; int choice,i; char ch='y'; while(1) { clrscr(); printf(" case 1: Create list"); printf(" case 2: Add in the list"); printf(" case 3: Delete in the list"); printf(" case 4: Append two list"); printf(" case 5: show list"); printf(" case 6: Exit"); printf(" Enter your choice : "); scanf("%d",&choice); switch(choice) { case 1: //create list while(ch!='n') { printf(" Enter element : "); scanf("%d",&i); create(&first,i); printf(" Enter element (y/n) : "); fflush(stdin); scanf("%c",&ch); } break; case 2: //add in the list int c; clrscr(); printf(" case 1: Add in Beginning"); printf(" case 2: Add in End"); printf(" case 3: Add After a given element"); printf(" case 4: Return to main menu"); printf(" Enter your choice : "); scanf("%d",&c); switch(c) { case 1: add_at_beg(&first); break; case 2: add_at_end(&first); break; case 3: add_after_given_element(&first); break; case 4: break; } break; case 3: clrscr(); printf(" case 1: Delete in Beginning"); printf(" case 2: Delete in End"); printf(" case 3: Delete a specified element"); printf(" case 4: Return to main menu"); printf(" Enter your choice : "); scanf("%d",&c); switch(c) { case 1: del_at_beg(&first); break; case 2: del_at_end(&first); break; case 3: del_specified_element(&first); break; case 4: break; } break; case 4: char ch='y'; printf("Enter element in second list : "); while(ch!='n') { printf(" Enter element : "); scanf("%d",&i); create(&second,i); printf(" Enter element (y/n) : "); fflush(stdin); scanf("%c",&ch); } append(&third,first,second); break; case 5: //show list clrscr(); printf(" case 1: List 1"); printf(" case 2: List 2"); printf(" case 3: List 3"); printf(" Enter choice : "); scanf("%d",&choice); switch(choice) { case 1: show(first);break; case 2: show(second);break; case 3: show(third);break; } break; case 6: exit(0); } } } ********************************* #include<conio.h> #include<stdio.h> #include<alloc.h> #include<stdlib.h> typedef struct list { int info; struct list *next; }; //.................Function Declaration ........... void create(struct list **p,int i) { struct list *temp,*q=*p; temp=(struct list*)malloc(sizeof(struct list)); temp->info=i; temp->next=NULL; if(*p==NULL) *p=temp; else { while(q->next!=NULL) q=q->next; q->next=temp; } } int append(struct list **t,struct list *f,struct list *s) { struct list *temp=*t; if(f==NULL && s==NULL) return 0; while(f) { create(t,f->info); f=f->next; } while(s) { create(t,s->info); s=s->next; } return 0; } void show(struct list *p) { if(p==NULL) printf(" List is Empty"); else while(p) { printf("%d ",p->info); p=p->next; } getch(); } void add_at_beg(struct list **l) { struct list *temp=(struct list *)malloc(sizeof(struct list)); printf(" Enter element : "); scanf("%d",&temp->info); temp->next=NULL; if(*l==NULL) *l=temp; else { temp->next=*l; *l=temp; } } void del_at_beg(struct list **l) { list *temp; if(*l==NULL) { printf(" List is empty"); getch(); } else { temp=*l; *l=(*l)->next; free(temp); } } void add_at_end(struct list **l) { list *temp,*p; temp=(struct list *)malloc(sizeof(struct list)); printf(" Enter element : "); scanf("%d",&temp->info); temp->next=NULL; if(*l==NULL) *l=temp; else { p=*l; while(p->next!=NULL) p=p->next; p->next=temp; } } void del_at_end(struct list **l) { list *temp,*p; if(*l==NULL) { printf(" List is Empty"); getch(); } else if((*l)->next==NULL) { temp=*l; *l=NULL; free(temp); } else { p=*l; while(p->next->next!=NULL) p=p->next; temp=p->next->next; p->next=NULL; free(temp); } } void add_after_given_element(list **l) { list *temp,*p; int m; temp=(struct list *)malloc(sizeof(struct list)); printf(" Enter element : "); scanf("%d",&temp->info); printf(" Enter position after which element inserted : "); scanf("%d",&m); temp->next=NULL; if(*l==NULL) *l=temp; else { p=*l; while(p->next!=NULL) if(p->info==m) break; else p=p->next; temp->next=p->next; p->next=temp; } } void del_specified_element(list **l) { list *temp,*p,*q; int m; printf(" Enter element which is deleted : "); scanf("%d",&m); if(*l==NULL) { printf(" List is Empty"); getch(); } else if((*l)->next!=NULL && (*l)->info==m) { temp=*l; *l=(*l)->next; free(temp); } else if((*l)->next==NULL && (*l)->info==m) { temp=*l; *l=NULL; free(temp); } else { p=*l; while(p!=NULL) if(p->info==m) break; else { q=p; p=p->next; } temp=p; q->next=p->next; free(temp); } }

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=614


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