-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDS4.C
More file actions
203 lines (75 loc) · 1.54 KB
/
Copy pathDS4.C
File metadata and controls
203 lines (75 loc) · 1.54 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
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
int a[20], F , R;
void insert()
{int num;
if ((F==0 && R==19) || (F==R+1))
{ printf("Overflow!!! \n");
getch();
exit(0); }
printf("Enter Number for Insertion \n");
scanf("%d" ,&num);
if (R==-1)
{ R++; F++; }
else if (R==19)
R = 0;
else
R++;
a[R] = num;
printf("Added! \n");
getch();
}
void Delete()
{ int num;
if (F==-1)
{ printf("Underflow");
getch();
exit(0); }
num = a[F];
if (F==R)
{ F=R=-1; }
else if (F==19)
F = 0;
else
F++;
printf("Deleted number is %d \n", num);
getch();
}
void display()
{int i,j;
if (F==-1)
printf("Underflow!!! \n");
else if (F==R)
printf("%d" ,a[F]);
else if (R>F)
for ( i=F; i<=R; i++)
printf("%d \n",a[i]);
else
for ( j=F; j<=19; j++)
printf("%d \n", a[j]);
getch();
}
void main()
{char ch;int op;
F=-1;
R=-1;
do { clrscr();
printf("Insert.....1 \n");
printf("Delete.....2 \n");
printf("Display....3 \n");
printf("Enter Choice");
scanf("%d",&op);
switch(op)
{ case 1 : insert();
break;
case 2 : Delete();
break;
case 3 : display();
break;
default: printf("Invalid Choice \n");
}
printf("Return to Main Menu? \n");fflush(stdin);
scanf("%c", &ch); } while (ch=='y' || ch=='Y');
getch();
}