Skip to content

Commit

Permalink
queue.c: Add queue in C
Browse files Browse the repository at this point in the history
Closes #56
  • Loading branch information
NeelavaChatterjee committed Dec 1, 2018
1 parent 52bd1ad commit a72a2d1
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ This repository contains examples of various algorithms written on different pro

| Data Structure | C | CPP | Java | Python |
|:----------------------------------------------------------------------------------------------- |:-------------------------------------:|:-------------------------------------:|:-------------------------------------:|:-------------------------------------:|
| [Queue](https://en.wikipedia.org/wiki/Queue_(abstract_data_type)) | | [:octocat:](queue/Cpp) | | |
| [Queue](https://en.wikipedia.org/wiki/Queue_(abstract_data_type)) | [:octocat:](queue/C) | [:octocat:](queue/Cpp) | | |
| [Stack](https://en.wikipedia.org/wiki/Stack_(abstract_data_type)) | [:octocat:](stack/C ) | | [:octocat:](stack/Java) | [:octocat:](stack/Python) |
| [Linear Linked List](https://en.wikipedia.org/wiki/Linked_list) | [:octocat:](linked_list/C) | [:octocat:](linked_list/Cpp) | [:octocat:](linked_list/Java) | [:octocat:](linked_list/Python) |
| [AVL Tree](https://en.wikipedia.org/wiki/AVL_tree) | [:octocat:](avl_tree/C) | [:octocat:](avl_tree/Cpp) | [:octocat:](avl_tree/Java) | [:octocat:](avl_tree/Python) |
Expand Down
61 changes: 61 additions & 0 deletions queue/C/queue.c
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');
}

2 comments on commit a72a2d1

@sangamcse
Copy link
Member

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.

Message File Line
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 5
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 6
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 11
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 12
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 17
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 18
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 19
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 20
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 25
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 26
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 31
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 32
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 37
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 38
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 43
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 44
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 45
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 46
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 47
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 48
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 49
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 50
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 51
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 52
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 53
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 54
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 55
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 56
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 57
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 58
Line contains following spacing inconsistencies: - Spaces used instead of tabs. queue/C/queue.c 60

Until GitMate provides an online UI to show a better overview, you can run coala locally for more details.

@sangamcse
Copy link
Member

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.

Message File Line
Missing spaces around = [whitespace/operators] [4] queue/C/queue.c 11
Missing spaces around = [whitespace/operators] [4] queue/C/queue.c 12
Missing spaces around == [whitespace/operators] [3] queue/C/queue.c 17
Missing space before ( in if( [whitespace/parens] [5] queue/C/queue.c 17
Missing spaces around == [whitespace/operators] [3] queue/C/queue.c 19
Missing space before ( in if( [whitespace/parens] [5] queue/C/queue.c 19
Missing spaces around = [whitespace/operators] [4] queue/C/queue.c 26
Missing spaces around = [whitespace/operators] [4] queue/C/queue.c 37
Missing spaces around < [whitespace/operators] [3] queue/C/queue.c 37
Missing space before ( in for( [whitespace/parens] [5] queue/C/queue.c 37
Missing space after , [whitespace/comma] [3] queue/C/queue.c 38
Missing space before { [whitespace/braces] [5] queue/C/queue.c 42
Missing spaces around = [whitespace/operators] [4] queue/C/queue.c 45
Missing spaces around < [whitespace/operators] [3] queue/C/queue.c 45
Missing space before ( in for( [whitespace/parens] [5] queue/C/queue.c 45

Until GitMate provides an online UI to show a better overview, you can run coala locally for more details.

Please sign in to comment.