SlideShare a Scribd company logo
1 of 6
C Program To Implement Linked List Using Array Abstract Data Type
#include<stdio.h>
#include<conio.h>
#include<alloc.h>
#include<stdlib.h>
voidcreate( )
voidinsert( )
voiddelete()
voiddisplay( )
struct node
{
intdata;
struct node *link;
};
struct node *first= NULL, *last= NULL, *next,*prev,*cur;
voidmain( )
{
intch;
clrscr( );
printf ("nSINGLYLINKED LIST");
do
{
printf ("n1.CREATE n 2.INSERTn 3.DELETE n 4.EXIT n");
printf ("nENTER YOUR CHOICE: ");
scanf ("%d",&ch );
switch(ch)
{
case 1:
create( );
display( );
break;
case 2:
insert( );
display( );
break;
case 3:
delete( );
display( );
break;
case 4:
exit(0);
}
} while( ch<= 3)
}
voidcreate( )
{
cur = ( struct node*)malloc(sizeof (structnode));
printf ("nENTER THE DATA:");
scanf ("%d", &cur?data);
cur?link= NULL;
first= cur;
last= cur;
}
voidinsert( )
{
intpos,c = 1;
cur = (structnode*)malloc(sizeof (structnode) );
printf (โ€œENTERTHE DATA :โ€);
scanf (โ€œ%dโ€,&cur?data);
printf(โ€œENTERTHE POSITION:โ€);
scanf (โ€œ%dโ€,&pos );
if ( (pos= = 1)&& (first!= NULL) )
{
cur?link= first;
first= cur;
}
else
{
next= first;
while (c< pos )
{
prev= next;
next= prev?link;
c++;
}
if ( prev= = NULL)
{
printf (โ€œnINVALIDPOSITION nโ€);
}
else
{
cur?link= prev?link;
prev?link =cur;
if (cur?link= = NULL)
{
last= cur;
}
}
}
}
voiddelete()
{
intpos,c=1;
printf (โ€œENTERTHE POSITION :โ€);
scanf (โ€œ%dโ€,&pos);
if (first= = NULL)
{
printf (โ€œnLIST IS EMPTY nโ€);
}
else if (pos= = 1&& first?link== NULL)
{
printf(โ€œNdeletedelementis%dnโ€,cur?data);
free(cur);
}
else
{
next= first;
while (c< pos )
{
prev= next;
next= next?link;
c++;
}
prev?link =next?link;
next?link=NULL;
if (next= = NULL)
{
printf (โ€œnINVALIDPOSITION nโ€œ);
}
else
{
printf (โ€œnDELETED ELEMENT IS%dnโ€,next?data);
free (next);
if(prev?link== NULL)
{
last= prev;
}
}
}
}
voiddisplay( )
{
cur = first;
while (cur!= NULL)
{
printf (โ€œn%dโ€,cur?data);
cur = cur?link;
}
}
C Program to implement List ADT using Arrays
#include<stdio.h>
#include<conio.h>
#define MAX 10
void create();
void insert();
void deletion();
void search();
void display();
int a,b[20], n, p, e, f, i, pos;
void main()
{
//clrscr();
int ch;
char g='y';
do
{
printf("n main Menu");
printf("n 1.Create n 2.Delete n 3.Search n 4.Insert n 5.Displayn 6.Exit n");
printf("n Enter your Choice");
scanf("%d", &ch);
switch(ch)
{
case 1:
create();
break;
case 2:
deletion();
break;
case 3:
search();
break;
case 4:
insert();
break;
case 5:
display();
break;
case 6:
exit();
break;
default:
printf("n Enter the correct choice:");
}
printf("n Do u want to continue:::");
scanf("n%c", &g);
}
while(g=='y'||g=='Y');
getch();
}
void create()
{
printf("n Enter the number of nodes");
scanf("%d", &n);
for(i=0;i<n;i++)
{
printf("n Enter the Element:",i+1);
scanf("%d", &b[i]);
}
}
void deletion()
{
printf("n Enter the position u want to delete::");
scanf("%d", &pos);
if(pos>=n)
{
printf("n Invalid Location::");
}
else
{
for(i=pos+1;i<n;i++)
{
b[i-1]=b[i];
}
n--;
}
printf("n The Elements after deletion");
for(i=0;i<n;i++)
{
printf("t%d", b[i]);
}
}
void search()
{
printf("n Enter the Element to be searched:");
scanf("%d", &e);
for(i=0;i<n;i++)
{
if(b[i]==e)
{
printf("Value is in the %d Position", i);
}
else
{
printf("Value %d is not in the list::", e);
continue;
}
}
}
void insert()
{
printf("n Enter the position u need to insert::");
scanf("%d", &pos);
if(pos>=n)
{
printf("n invalid Location::");
}
else
{
for(i=MAX-1;i>=pos-1;i--)
{
b[i+1]=b[i];
}
printf("n Enter the element to insert::n");
scanf("%d",&p);
b[pos]=p;
n++;
}
printf("n The list after insertion::n");
display();
}
void display()
{
printf("n The Elements of The list ADT are:");
for(i=0;i<n;i++)
{
printf("nn%d", b[i]);
}
}

More Related Content

What's hot

Fundamentals of data structures ellis horowitz & sartaj sahni
Fundamentals of data structures   ellis horowitz & sartaj sahniFundamentals of data structures   ellis horowitz & sartaj sahni
Fundamentals of data structures ellis horowitz & sartaj sahni
Hitesh Wagle
ย 
Function in c
Function in cFunction in c
Function in c
Raj Tandukar
ย 

What's hot (20)

Fundamentals of data structures ellis horowitz & sartaj sahni
Fundamentals of data structures   ellis horowitz & sartaj sahniFundamentals of data structures   ellis horowitz & sartaj sahni
Fundamentals of data structures ellis horowitz & sartaj sahni
ย 
Union in C programming
Union in C programmingUnion in C programming
Union in C programming
ย 
User defined function in c
User defined function in cUser defined function in c
User defined function in c
ย 
C++ 25 programs Class XII
C++ 25 programs Class XIIC++ 25 programs Class XII
C++ 25 programs Class XII
ย 
Function in c
Function in cFunction in c
Function in c
ย 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
ย 
Introduction to data structure ppt
Introduction to data structure pptIntroduction to data structure ppt
Introduction to data structure ppt
ย 
Python collections
Python collectionsPython collections
Python collections
ย 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
ย 
List and Dictionary in python
List and Dictionary in pythonList and Dictionary in python
List and Dictionary in python
ย 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
ย 
C pointer
C pointerC pointer
C pointer
ย 
Structures in c language
Structures in c languageStructures in c language
Structures in c language
ย 
Strings in c
Strings in cStrings in c
Strings in c
ย 
Function Pointer
Function PointerFunction Pointer
Function Pointer
ย 
String in c
String in cString in c
String in c
ย 
Queue ppt
Queue pptQueue ppt
Queue ppt
ย 
DATA STRUCTURES
DATA STRUCTURESDATA STRUCTURES
DATA STRUCTURES
ย 
Built in function
Built in functionBuilt in function
Built in function
ย 
File in C language
File in C languageFile in C language
File in C language
ย 

Similar to C program to implement linked list using array abstract data type

C basics
C basicsC basics
C basics
MSc CST
ย 
C lab manaual
C lab manaualC lab manaual
C lab manaual
manoj11manu
ย 
systems programming lab programs in c
systems programming lab programs in csystems programming lab programs in c
systems programming lab programs in c
Meghna Roy
ย 
C program
C programC program
C program
Komal Singh
ย 
SaraPIC
SaraPICSaraPIC
SaraPIC
Sara Sahu
ย 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
Azhar Javed
ย 

Similar to C program to implement linked list using array abstract data type (20)

One dimensional operation of Array in C- language
One dimensional operation of Array in C- language One dimensional operation of Array in C- language
One dimensional operation of Array in C- language
ย 
C basics
C basicsC basics
C basics
ย 
Array imp of list
Array imp of listArray imp of list
Array imp of list
ย 
Circular linked list
Circular linked listCircular linked list
Circular linked list
ย 
Double linked list
Double linked listDouble linked list
Double linked list
ย 
Single linked list
Single linked listSingle linked list
Single linked list
ย 
C programms
C programmsC programms
C programms
ย 
Data Structure in C Programming Language
Data Structure in C Programming LanguageData Structure in C Programming Language
Data Structure in C Programming Language
ย 
ADA FILE
ADA FILEADA FILE
ADA FILE
ย 
week-6x
week-6xweek-6x
week-6x
ย 
Data Structure using C
Data Structure using CData Structure using C
Data Structure using C
ย 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
ย 
Data struture lab
Data struture labData struture lab
Data struture lab
ย 
C lab manaual
C lab manaualC lab manaual
C lab manaual
ย 
systems programming lab programs in c
systems programming lab programs in csystems programming lab programs in c
systems programming lab programs in c
ย 
Circular queue
Circular queueCircular queue
Circular queue
ย 
C program
C programC program
C program
ย 
C Programming lab
C Programming labC Programming lab
C Programming lab
ย 
SaraPIC
SaraPICSaraPIC
SaraPIC
ย 
Chapter 8 c solution
Chapter 8 c solutionChapter 8 c solution
Chapter 8 c solution
ย 

Recently uploaded

Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
KreezheaRecto
ย 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
SUHANI PANDEY
ย 
Call Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service
Call Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort ServiceCall Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service
Call Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service
9953056974 Low Rate Call Girls In Saket, Delhi NCR
ย 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Christo Ananth
ย 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
ย 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ankushspencer015
ย 
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar โ‰ผ๐Ÿ” Delhi door step de...
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar  โ‰ผ๐Ÿ” Delhi door step de...Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar  โ‰ผ๐Ÿ” Delhi door step de...
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar โ‰ผ๐Ÿ” Delhi door step de...
9953056974 Low Rate Call Girls In Saket, Delhi NCR
ย 

Recently uploaded (20)

Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
ย 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
ย 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
ย 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
ย 
Top Rated Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth โŸŸ 6297143586 โŸŸ Call Me For Genuine Se...
ย 
Call Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service
Call Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort ServiceCall Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service
Call Girls in Ramesh Nagar Delhi ๐Ÿ’ฏ Call Us ๐Ÿ”9953056974 ๐Ÿ” Escort Service
ย 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
ย 
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete RecordCCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
CCS335 _ Neural Networks and Deep Learning Laboratory_Lab Complete Record
ย 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
ย 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
ย 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
ย 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
ย 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
ย 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
ย 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
ย 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
ย 
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Walvekar Nagar Call Me 7737669865 Budget Friendly No Advance Booking
ย 
Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
ย 
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar โ‰ผ๐Ÿ” Delhi door step de...
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar  โ‰ผ๐Ÿ” Delhi door step de...Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar  โ‰ผ๐Ÿ” Delhi door step de...
Call Now โ‰ฝ 9953056974 โ‰ผ๐Ÿ” Call Girls In New Ashok Nagar โ‰ผ๐Ÿ” Delhi door step de...
ย 
Thermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - VThermal Engineering-R & A / C - unit - V
Thermal Engineering-R & A / C - unit - V
ย 

C program to implement linked list using array abstract data type

  • 1. C Program To Implement Linked List Using Array Abstract Data Type #include<stdio.h> #include<conio.h> #include<alloc.h> #include<stdlib.h> voidcreate( ) voidinsert( ) voiddelete() voiddisplay( ) struct node { intdata; struct node *link; }; struct node *first= NULL, *last= NULL, *next,*prev,*cur; voidmain( ) { intch; clrscr( ); printf ("nSINGLYLINKED LIST"); do { printf ("n1.CREATE n 2.INSERTn 3.DELETE n 4.EXIT n"); printf ("nENTER YOUR CHOICE: "); scanf ("%d",&ch ); switch(ch) { case 1: create( ); display( ); break; case 2: insert( ); display( ); break; case 3: delete( ); display( ); break; case 4: exit(0); } } while( ch<= 3) } voidcreate( ) { cur = ( struct node*)malloc(sizeof (structnode)); printf ("nENTER THE DATA:");
  • 2. scanf ("%d", &cur?data); cur?link= NULL; first= cur; last= cur; } voidinsert( ) { intpos,c = 1; cur = (structnode*)malloc(sizeof (structnode) ); printf (โ€œENTERTHE DATA :โ€); scanf (โ€œ%dโ€,&cur?data); printf(โ€œENTERTHE POSITION:โ€); scanf (โ€œ%dโ€,&pos ); if ( (pos= = 1)&& (first!= NULL) ) { cur?link= first; first= cur; } else { next= first; while (c< pos ) { prev= next; next= prev?link; c++; } if ( prev= = NULL) { printf (โ€œnINVALIDPOSITION nโ€); } else { cur?link= prev?link; prev?link =cur; if (cur?link= = NULL) { last= cur; } } } } voiddelete() { intpos,c=1; printf (โ€œENTERTHE POSITION :โ€); scanf (โ€œ%dโ€,&pos); if (first= = NULL) { printf (โ€œnLIST IS EMPTY nโ€);
  • 3. } else if (pos= = 1&& first?link== NULL) { printf(โ€œNdeletedelementis%dnโ€,cur?data); free(cur); } else { next= first; while (c< pos ) { prev= next; next= next?link; c++; } prev?link =next?link; next?link=NULL; if (next= = NULL) { printf (โ€œnINVALIDPOSITION nโ€œ); } else { printf (โ€œnDELETED ELEMENT IS%dnโ€,next?data); free (next); if(prev?link== NULL) { last= prev; } } } } voiddisplay( ) { cur = first; while (cur!= NULL) { printf (โ€œn%dโ€,cur?data); cur = cur?link; } }
  • 4. C Program to implement List ADT using Arrays #include<stdio.h> #include<conio.h> #define MAX 10 void create(); void insert(); void deletion(); void search(); void display(); int a,b[20], n, p, e, f, i, pos; void main() { //clrscr(); int ch; char g='y'; do { printf("n main Menu"); printf("n 1.Create n 2.Delete n 3.Search n 4.Insert n 5.Displayn 6.Exit n"); printf("n Enter your Choice"); scanf("%d", &ch); switch(ch) { case 1: create(); break; case 2: deletion(); break; case 3: search(); break; case 4: insert(); break; case 5: display(); break; case 6: exit(); break; default: printf("n Enter the correct choice:"); } printf("n Do u want to continue:::"); scanf("n%c", &g);
  • 5. } while(g=='y'||g=='Y'); getch(); } void create() { printf("n Enter the number of nodes"); scanf("%d", &n); for(i=0;i<n;i++) { printf("n Enter the Element:",i+1); scanf("%d", &b[i]); } } void deletion() { printf("n Enter the position u want to delete::"); scanf("%d", &pos); if(pos>=n) { printf("n Invalid Location::"); } else { for(i=pos+1;i<n;i++) { b[i-1]=b[i]; } n--; } printf("n The Elements after deletion"); for(i=0;i<n;i++) { printf("t%d", b[i]); } } void search() { printf("n Enter the Element to be searched:"); scanf("%d", &e); for(i=0;i<n;i++) { if(b[i]==e) { printf("Value is in the %d Position", i); } else { printf("Value %d is not in the list::", e); continue;
  • 6. } } } void insert() { printf("n Enter the position u need to insert::"); scanf("%d", &pos); if(pos>=n) { printf("n invalid Location::"); } else { for(i=MAX-1;i>=pos-1;i--) { b[i+1]=b[i]; } printf("n Enter the element to insert::n"); scanf("%d",&p); b[pos]=p; n++; } printf("n The list after insertion::n"); display(); } void display() { printf("n The Elements of The list ADT are:"); for(i=0;i<n;i++) { printf("nn%d", b[i]); } }