SlideShare a Scribd company logo
4
Most read
5
Most read
6
Most read
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 (20)

PPTX
Unit I-Data Structures_Intoduction.pptx
DrkhanchanaR
 
PPTX
Dfs presentation
Alizay Khan
 
PPTX
Java string handling
Salman Khan
 
PPT
Control structure C++
Anil Kumar
 
PPTX
Association agggregation and composition
baabtra.com - No. 1 supplier of quality freshers
 
PDF
UNIT I LINEAR DATA STRUCTURES – LIST
Kathirvel Ayyaswamy
 
PPTX
Templates in c++
ThamizhselviKrishnam
 
PPTX
Templates in c++
Mayank Bhatt
 
PPTX
Unit 2 linked list
DrkhanchanaR
 
PPTX
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
DrkhanchanaR
 
PPTX
Java packages
BHUVIJAYAVELU
 
PPTX
Searching
Ashim Lamichhane
 
PPTX
Queues
Ashim Lamichhane
 
PPT
Top down parsing
ASHOK KUMAR REDDY
 
PPTX
queue & its applications
somendra kumar
 
PPTX
Circular Queue data structure
Dhananjaysinh Jhala
 
PDF
Time and Space Complexity
Ashutosh Satapathy
 
PPTX
Array of objects.pptx
RAGAVIC2
 
PPTX
Realibity design
Abhishek Tiwari
 
Unit I-Data Structures_Intoduction.pptx
DrkhanchanaR
 
Dfs presentation
Alizay Khan
 
Java string handling
Salman Khan
 
Control structure C++
Anil Kumar
 
Association agggregation and composition
baabtra.com - No. 1 supplier of quality freshers
 
UNIT I LINEAR DATA STRUCTURES – LIST
Kathirvel Ayyaswamy
 
Templates in c++
ThamizhselviKrishnam
 
Templates in c++
Mayank Bhatt
 
Unit 2 linked list
DrkhanchanaR
 
Unit I- Data structures Introduction, Evaluation of Algorithms, Arrays, Spars...
DrkhanchanaR
 
Java packages
BHUVIJAYAVELU
 
Searching
Ashim Lamichhane
 
Top down parsing
ASHOK KUMAR REDDY
 
queue & its applications
somendra kumar
 
Circular Queue data structure
Dhananjaysinh Jhala
 
Time and Space Complexity
Ashutosh Satapathy
 
Array of objects.pptx
RAGAVIC2
 
Realibity design
Abhishek Tiwari
 

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

DOC
Final ds record
Ganisius Ganish
 
PPTX
8.DATA STRUCTURES UNIT 1 AND 2 CS3301PPT.pptx
venigkrish89
 
PPTX
EC2311 – Data Structures and C Programming
Padma Priya
 
DOCX
What is Linked List in C.docx
nona800027
 
DOCX
Array imp of list
Elavarasi K
 
DOCX
01 list using array
SivakamiRaja1
 
PDF
TutorialII_Updated____niceupdateprogram.pdf
BappyAgarwal
 
PDF
Solution#includestdio.h#includeconio.h#includealloc.h.pdf
poddaranand1
 
DOCX
Linked list imp of list
Elavarasi K
 
PPTX
Ll.pptx
chin463670
 
PPTX
linked list.pptx
chin463670
 
PPT
Linked list1.ppt
KasthuriKAssistantPr
 
PPT
Unit ii(dsc++)
Durga Devi
 
PPTX
UNIT I LINEAR DATA STRUCTURES – LIST .pptx
VISWANATHAN R V
 
PPT
Unit7 C
arnold 7490
 
PDF
Linked list
A. S. M. Shafi
 
PPTX
Linked list
KalaivaniKS1
 
PPTX
Adt of lists
Nivegeetha
 
PPTX
linkedlistforslideshare-210123143943.pptx
shesnasuneer
 
PPT
DS Unit 2.ppt
JITTAYASHWANTHREDDY
 
Final ds record
Ganisius Ganish
 
8.DATA STRUCTURES UNIT 1 AND 2 CS3301PPT.pptx
venigkrish89
 
EC2311 – Data Structures and C Programming
Padma Priya
 
What is Linked List in C.docx
nona800027
 
Array imp of list
Elavarasi K
 
01 list using array
SivakamiRaja1
 
TutorialII_Updated____niceupdateprogram.pdf
BappyAgarwal
 
Solution#includestdio.h#includeconio.h#includealloc.h.pdf
poddaranand1
 
Linked list imp of list
Elavarasi K
 
Ll.pptx
chin463670
 
linked list.pptx
chin463670
 
Linked list1.ppt
KasthuriKAssistantPr
 
Unit ii(dsc++)
Durga Devi
 
UNIT I LINEAR DATA STRUCTURES – LIST .pptx
VISWANATHAN R V
 
Unit7 C
arnold 7490
 
Linked list
A. S. M. Shafi
 
Linked list
KalaivaniKS1
 
Adt of lists
Nivegeetha
 
linkedlistforslideshare-210123143943.pptx
shesnasuneer
 
DS Unit 2.ppt
JITTAYASHWANTHREDDY
 
Ad

Recently uploaded (20)

PDF
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
PDF
20ES1152 Programming for Problem Solving Lab Manual VRSEC.pdf
Ashutosh Satapathy
 
PPTX
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PDF
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
PPTX
Presentation 2.pptx AI-powered home security systems Secure-by-design IoT fr...
SoundaryaBC2
 
PPTX
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
PDF
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
PPTX
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
PDF
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
PDF
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
PPTX
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
PPTX
Introduction to Design of Machine Elements
PradeepKumarS27
 
PPTX
Water Resources Engineering (CVE 728)--Slide 3.pptx
mohammedado3
 
PPTX
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
PPTX
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
PPTX
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
DOC
MRRS Strength and Durability of Concrete
CivilMythili
 
PPTX
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
PPTX
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
PDF
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
AN EMPIRICAL STUDY ON THE USAGE OF SOCIAL MEDIA IN GERMAN B2C-ONLINE STORES
ijait
 
20ES1152 Programming for Problem Solving Lab Manual VRSEC.pdf
Ashutosh Satapathy
 
GitOps_Without_K8s_Training_detailed git repository
DanialHabibi2
 
PORTFOLIO Golam Kibria Khan — architect with a passion for thoughtful design...
MasumKhan59
 
Presentation 2.pptx AI-powered home security systems Secure-by-design IoT fr...
SoundaryaBC2
 
fatigue in aircraft structures-221113192308-0ad6dc8c.pptx
aviatecofficial
 
Electrical Machines and Their Protection.pdf
Nabajyoti Banik
 
Shinkawa Proposal to meet Vibration API670.pptx
AchmadBashori2
 
Halide Perovskites’ Multifunctional Properties: Coordination Engineering, Coo...
TaameBerhe2
 
Basic_Concepts_in_Clinical_Biochemistry_2018كيمياء_عملي.pdf
AdelLoin
 
Lecture 1 Shell and Tube Heat exchanger-1.pptx
mailforillegalwork
 
Introduction to Design of Machine Elements
PradeepKumarS27
 
Water Resources Engineering (CVE 728)--Slide 3.pptx
mohammedado3
 
Element 11. ELECTRICITY safety and hazards
merrandomohandas
 
What is Shot Peening | Shot Peening is a Surface Treatment Process
Vibra Finish
 
Mechanical Design of shell and tube heat exchangers as per ASME Sec VIII Divi...
shahveer210504
 
MRRS Strength and Durability of Concrete
CivilMythili
 
How Industrial Project Management Differs From Construction.pptx
jamespit799
 
澳洲电子毕业证澳大利亚圣母大学水印成绩单UNDA学生证网上可查学历
Taqyea
 
Introduction to Productivity and Quality
মোঃ ফুরকান উদ্দিন জুয়েল
 
Ad

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]); } }