Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Standard view
Full view
of .
Look up keyword
Like this
0 of .
Results for:
No results containing your search query
P. 1
C program for list implementation using linked list

C program for list implementation using linked list



|Views: 24,698|Likes:
Published by Saiyasodharan
C program for list implementation using linked list
C program for list implementation using linked list

More info:

Published by: Saiyasodharan on Mar 24, 2009
Copyright:Public Domain


Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less





#include<stdio.h>#include<stlib.h>#include<conio.h>struct node;typedef struct node *ptr;typedef ptr list;typedef ptr position;typedef int data;struct node{data element;struct node *next;}//function prototypesvoid makeempty(void);//to make empty listint isempty(void);//to check list is empty or notvoid create(void);//to create initial set of elements position findprevious(data);//to find position of previous elementvoid delet(data);//to delete given elementvoid display(void);//to display all the elementsvoid insert(data, int);//to insert a new element position getprevposition(int);//to find position of previous elementdata getelement(int);//to find the element at given positionint getposition(data);//to find position of given element//global variable declarations position first; position last; position L;int length;//to make empty listvoid makeempty(void){ position tmp;tmp = malloc(sizeof(list));tmp->next = NULL;L = tmp;first = last = NULL;}//to check list is empty or not
int isempty(void){if (L->next = NULL)return 1;elsereturn 0;}//to create initial set of elementsvoid create(void){data e;int n, i; position tmp;makeempty(); printf(“Enter number of element : \“);scanf(“%d”, &n);for (i=0; i<n; i++){ printf(“Enter an element : “);scanf(“%d”, &e);tmp = malloc(sizeof(list));tmp->element = e;tmp->next = NULL;if (L->next == NULL){L->next = tmp;first = last = tmp;}else{last->next = tmp;last = tmp;}}}//to display all the elementsvoid display(){ position t;for(t=first; t!=NULL; t=t->next) printf(“%d --> “, t->element);getch();}//to find position of previous element position getprevposition(int index){ position tmp;int count = 1;
if (index>length){ printf(“Invalid Position”);return NULL;}else{for (tmp=first; count<index-1; tmp=tmp->next)count++;return tmp;}}//to insert a new elementvoid insert(data x, int p){ position pos, tmp;tmp = malloc(sizeof(list));tmp->element=x;if (p==1)//first position{tmp->next = first;L->next = tmp;first = tmp;length++;}else if (p == length)//last position{last->next = tmp;last = tmp;tmp->next = NULL;}else//arbitrary position{ pos = getpreviousposition(p);if (pos == NULL){ printf(“Invalid position”);getch();}else{tmp->next = pos->next; pos->next = tmp;length++;}}}//to find position of previous element

Activity (110)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
Vaibhav Sharma liked this
Elson Kwon liked this
Elson Kwon liked this
ganesh_krishna added this note
is reading find largest collection of c programs at c programs examples - www.itstudentjunction.com.
Tamilarasutamil liked this
Aditya Sharma liked this

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->