forked from shanilla9605kh/C-Programs
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathP4.cpp
More file actions
96 lines (89 loc) · 2.39 KB
/
P4.cpp
File metadata and controls
96 lines (89 loc) · 2.39 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
#include<stdio.h>
#include<conio.h>
int queue[5],front=-1,rear=-1;
void insert()
{ int data;
if(rear==4)
{ printf("\n ------------------------------------");
printf("\n Overflow !!!"); }
else if(front==-1&&rear==-1)
{ printf("\n\n Enter Data : ");
scanf("%d",&data);
front=rear=0;
queue[rear]=data;
printf("\n ------------------------------------");
printf("\n Data entered successfully.");
}
else
{ printf("\n\n Enter Data : ");
scanf("%d",&data);
rear++;
queue[rear]=data;
printf("\n ------------------------------------");
printf("\n Data entered successfully.");
}
printf("\n ------------------------------------");
}
void deletehead()
{ printf("\n ------------------------------------");
if(front==-1&&rear==-1)
{ printf("\n List is Empty !!!"); }
else if(front==rear)
{ front=rear=-1;
printf("\n Deleted successfully.");
printf("\n List is Empty !!!");
}
else
{ front++;
printf("\n Deleted successfully.");
}
printf("\n ------------------------------------");
}
}
int main()
{
int n;
printf("Enter the number of elements: "); scanf("%d",&n);
printf("Fibonacci Series: "); printf("%d %d ", 0, 1);
printFibonacci(n-2); //n-2 because 2 numbers are already printed return 0;
void displayqueue()
{ int i=1;
printf("\n ------------------------------------");
if(front==-1&&rear==-1)
{ printf("\n List is Empty !!!"); }
else
{ for(i=front;i<rear+1;i++)
{ printf("\n Node %d : %d",i+1,queue[i]); }
}
printf("\n ------------------------------------");
}
int main()
{ int c=0,d,count=0;
do
{ if(front==-1&&rear==-1)
{ count=0; }
else
{ count=rear-front+1; }
printf("\n\n\t -: Array Queue Menu :-");
printf("\n\n 1. Enter Data ----------");
printf("\n 2. Display Queue | Status |");
printf("\n 3. Delete Head | (%d/5) |",count);
printf("\n 4. Quit ----------");
printf("\n\n Enter choice number : ");
scanf("%d",&c);
switch(c)
{ case 1 : insert();
break;
case 2 : displayqueue();
break;
case 3 : deletehead();
break;
case 4 : break;
default : printf("\n ------------------------------------");
printf("\n\n Invalid input !!!");
printf("\n ------------------------------------");
}
}while(c!=4);
printf("\n\n Press any key to EXIT...");
return 0;
}