Repository navigation
Expand file tree
/
Copy pathaarayinsertdelete (2).c
More file actions
154 lines (154 loc) · 2.94 KB
/
Copy pathaarayinsertdelete (2).c
File metadata and controls
154 lines (154 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#define LIST_SIZE 30
void main()
{
int *element=NULL;
int ch,i,j,n;
int insdata,deldata,moddata,found;
int top=-1;
element=(int*)malloc(sizeof(int)* LIST_SIZE);
while(1)
{
fflush(stdin);
printf("\n\n basic Operations in a Linear List......");
printf("\n 1.Create New List \t 2.Modify List \t 3.View List");
printf("\n 4.Insert First \t 5.Insert Last \t 6.Insert Middle");
printf("\n 7.Delete First \t 8.Delete Last \t 9.Delete Middle");
printf("\nEnter the Choice 1 to 10 : ");
scanf("%d",&ch);
switch(ch)
{
case 1:
top=-1;
printf("\n Enter the Limit (How many Elements):");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n Enter The Element [%d]:",(i+1));
scanf("%d",&element[++top]);
}
break;
case 2:
if(top==-1)
{
printf("\n Linear List is Empty:");
break;
}
printf("\n Enter the Element for Modification:");
scanf("%d",&moddata);
found=0;
for(i=0;i<=top;i++)
{
if(element[i]==moddata)
{
found=1;
printf("\n Enter The New Element :");
scanf("%d",&element[i]);
break;
}
}
if(found==0)
printf("\n Element %d not found",moddata);
break;
case 3:
if(top==-1)
printf("\n \n Linear List is Empty:");
else if(top==LIST_SIZE -1)
printf("\n Linear LIst is Full:");
for(i=0;i<=top;i++)
printf("\n Element[%d]is-->%d",(i+1),element[i]);
break;
case 4:
if(top==LIST_SIZE-1)
{
printf("\n Linear List is Full:");
break;
}
top++;
for(i=top;i>0;i--)
element[i]=element[i-1];
printf("\n Enter the Element:");
scanf("%d",&element[0]);
break;
case 5:
if(top==LIST_SIZE-1)
{
printf("\n Linear List is Full:");
break;
}
printf("\n Enter the Element:");
scanf("%d",&element[++top]);
break;
case 6:
if(top==LIST_SIZE-1)
printf("\n Linear List is Full:");
else if(top==-1)
printf("\n linear List is Empty.");
else
{
found=0;
printf("\n Enter the Element after which the insertion is to be made:");
scanf("%d",&insdata);
for(i=0;i<=top;i++)
if(element[i]==insdata)
{
found=1;
top++;
for(j=top;j>i;j--)
element[j]=element[j-1];
printf("\n Enter the Element :");
scanf("%d",&element[i+1]);
break;
}
if(found==0)
printf("\n Element %d Not Found",insdata);
}
break;
case 7:
if(top==-1)
{
printf("\n Linear List is Empty:");
break;
}
printf("\n Deleted Data-->Element :%d",element[0]);
top--;
for(i=0;i<=top;i++)
element[i]=element[i+1];
break;
case 8:
if(top==-1)
printf("\n Linear List is Empty:");
else
printf("\n Deleted Data-->Element :%d",element[top--]);
break;
case 9:
if(top==-1)
{
printf("\n Linear List is Empty:");
break;
}
printf("\n Enter the Element for Deletion :");
scanf("%d",&deldata);
found=0;
for(i=0;i<=top;i++)
if(element[i]==deldata)
{
found=1;
printf("\n Deleted data-->Element :%d",element[i]);
top--;
for(j=i;j<=top;j++)
element[j]=element[j+1];
break;
}
if(found==0)
printf("\n Element %d Not Found ",deldata);
break;
default:
free(element);
printf("\n End Of Run Of Your Program.........");
exit(0);
}
}
}