-
Notifications
You must be signed in to change notification settings - Fork 302
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
62 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#include<stdio.h> | ||
|
||
// Queue structure | ||
struct queue { | ||
int arr[10]; | ||
int front, end; | ||
}; | ||
|
||
// Initialize the queue | ||
void init(struct queue *st) { | ||
st->front=0; | ||
st->end=0; | ||
} | ||
|
||
// Method to check if the queue st is full or empty | ||
void check(struct queue *st) { | ||
if(st->front==0 && st->end==0) | ||
printf("The queue is empty!!!!\n"); | ||
else if(st->end==10) | ||
printf("The queue is full!!!!\n"); | ||
} | ||
|
||
// Method to insert elements in the queue st | ||
void enqueue(struct queue *st, int ele) { | ||
check(st); | ||
st->arr[(st->end)++]=ele; | ||
} | ||
|
||
// Method to remove first element from the queue st | ||
int dequeue(struct queue *st) { | ||
check(st); | ||
return st->arr[(st->front)++]; | ||
} | ||
|
||
// Method to show elements in the queue st | ||
void show(struct queue st) { | ||
for(int i=st.front; i<st.end; i++) | ||
printf("%d",st.arr[i]); | ||
} | ||
|
||
// Driver method | ||
void main(){ | ||
struct queue st; | ||
init(&st); | ||
for(int i=1; i<9; i++) | ||
enqueue(&st, i); | ||
show(st); | ||
putchar('\n'); | ||
printf("%d\n", dequeue(&st)); | ||
enqueue(&st, 6); | ||
show(st); | ||
putchar('\n'); | ||
enqueue(&st, 9); | ||
show(st); | ||
putchar('\n'); | ||
printf("%d\n", dequeue(&st)); | ||
printf("%d\n", dequeue(&st)); | ||
printf("%d\n", dequeue(&st)); | ||
|
||
putchar('\n'); | ||
} |
a72a2d1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment on a72a2d1.
There are 31 results for the section all.cpp. They have been shortened and will not be shown inline because they are more than 10.
Until GitMate provides an online UI to show a better overview, you can run coala locally for more details.
a72a2d1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment on a72a2d1.
There are 15 results for the section all.cpplint. They have been shortened and will not be shown inline because they are more than 10.
Until GitMate provides an online UI to show a better overview, you can run coala locally for more details.