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

Home » C Home » Beginners / Lab Assignments Home » link list basic operations

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

Search Projects & Source Codes:

Title link list basic operations
Author praveen nair
Author Email prashantkch_999 [at] yahoo.com
Description
Category C » Beginners / Lab Assignments
Hits 364453
Code Select and Copy the Code
Code : # include<stdio.h> # include<conio.h> # include "malloc.h" struct node { int data; struct node *link; }; void main() { int a=111,b=2,c=3,will,wish,num; struct node *ptr,*ptr2,*result,*temp; void add(struct node **,int ); struct node * search(struct node *); void display(struct node *); void invert(struct node *); void del(struct node *,int); struct node * concat(struct node *,struct node *); ptr=NULL; ptr2=NULL; result=NULL; //result for storing the result of concatenation clrscr(); will=1; while(will==1) { printf(" Main Menu 1. Add element 2.Delete element 3.Search element 4Linked List concatenation 5.Invert linked list 6. Display elements Please enter the choice"); scanf("%d",&wish); switch(wish) { case 1: printf(" Enter the element you want to add "); scanf("%d",&num); add(&ptr,num); display(ptr); break; case 2: printf(" Enter the element to delete "); scanf("%d",&num); del(ptr,num); break; case 3: printf(" Now demonstrating search "); temp = search(ptr); printf(" Address of first occurence is %u ",temp); break; case 4: /* Inputs given internally for demo only */ printf(" Now demonstrating linked list concatenation Press any key to continue..."); add(&ptr2,2); add(&ptr2,4); add(&ptr2,6); getch(); printf(" Displaying second Linked List "); display(ptr2); getch(); result = concat(ptr,ptr2); clrscr(); printf(" Now Displaying the result of concatenation"); display(result); getch(); break; case 5: printf(" Inverting the list ... Press any key to continue..."); invert(ptr); break; case 6: display(ptr); break; default: printf(" Illegal choice "); } printf(" DO you want to continue ( press 1 for yes "); scanf("%d",&will); } //end of while } void add(struct node **q,int num) { struct node *temp; temp = *q; if(*q==NULL) { *q=malloc(sizeof(struct node)); temp = *q; } else { while((temp->link)!=NULL) { temp=temp->link; } temp->link = malloc(sizeof(struct node)); temp=temp->link; } temp->data = num; temp->link = NULL; } void display(struct node *pt) { while(pt!=NULL) { printf(" Data : %d",pt->data); printf(" Link : %d",pt->link); pt=pt->link; } } void invert(struct node *ptr) { struct node *p,*q,*r; p=ptr; q=NULL; while(p!=NULL) { r=q; q=p; p=p->link; q->link=r; } ptr = q; display(ptr); } // CONCATENATION OF LINKED LISTS struct node * concat(struct node *p,struct node *q) { struct node *x,*r; if (p==NULL) r=q; if (q==NULL) r=p; else { x=p; r=x; while(x->link!=NULL) x=x->link; x->link=q; } return(r); } // SEARCHING AN ELEMENT IN THE LINKED LIST // THIS FUNCTION FINDS THE FIRST OCCURENCE OF // A DATA AND RETURNS A POINTER TO ITS ADDRESS struct node * search(struct node *p) { struct node *temp; int num; temp = p; printf(" Enter the data that you want to search "); scanf("%d",&num); printf(" Link of temp %u", temp->link); while(temp->link!=NULL) { printf(" In while "); if(temp->data == num) return(temp); temp=temp->link; } return(NULL); } // DELETING DATA FROM THE LINKED LIST// void del(struct node *p,int num) { struct node *temp,*x; temp=p; x= NULL; while (temp->link !=NULL) { if(temp->data == num) { if (x==NULL) { p = temp->link; free(temp); return; } else { x->link = temp->link; free(temp); return; } } //end of outer if x=temp; temp=temp->link; } //end of while printf(" No such entry to delete "); } //end of fn.

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


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