-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99c8dab
commit a866a11
Showing
1 changed file
with
29 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#include <stdio.h> | ||
int rear = -1; | ||
int front = -1; | ||
int addq(int* queue, int value); | ||
int deleteq(int* queue); | ||
|
||
int main() { | ||
int arr[10]; | ||
for (int i = 0; i < 10; i++) addq(arr, i); | ||
for (int i = front + 1; i < 10; i++) printf("%d ", arr[i]); | ||
printf("\nrear: %d", rear); | ||
return 0; | ||
} | ||
|
||
int addq(int* queue, int value) { | ||
if (rear >= 9) { | ||
if (front == -1) return printf("Queue is Full"); | ||
for (int i = front + 1; i <= rear; i++) queue[i - front - 1] = queue[i]; | ||
rear = rear - front - 1; | ||
front = -1; | ||
queue[++rear] = value; | ||
} | ||
else queue[++rear] = value; | ||
} | ||
|
||
int deleteq(int* queue) { | ||
if (front == rear) return printf("Queue is Empty"); | ||
return queue[++front]; | ||
} |