-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added priority_queue.c #3798
base: master
Are you sure you want to change the base?
added priority_queue.c #3798
Conversation
Same as your other PRs. |
removed header <conio.h>,global variable and fixed indentation errors
@@ -0,0 +1,93 @@ | |||
#include <stdio.h> | |||
|
|||
int head = 0,tail = 0; |
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.
Is there any way you can avoid global variables here?
|
||
else if (tail<max) { | ||
queue[0][tail]=value; | ||
queue[1][tail[=priority; |
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.
Type. Also, you need spaces after all commas in this file.
void | ||
dequeue(int max) | ||
{ | ||
if (tail==0 || head==max) {\ |
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.
This code doesn't work. Why do you have braces in the first place? And why the backslash?
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.
that backslash and brace is a typo..!
printf("queue is empty"); | ||
|
||
else { | ||
int i; |
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.
What is this?
void | ||
display() | ||
{ | ||
int i; |
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.
No need for this to be at the top of the function.
printf("queue is empty"); | ||
|
||
else { | ||
for (i=head;i<tail;i++) |
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.
Preincrement.
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.
why preincrement?
|
||
else { | ||
for (i=head;i<tail;i++) | ||
{ |
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.
Remove braces.
int i; | ||
if (tail==0) | ||
printf("queue is empty"); | ||
|
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.
Extra newline.
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.
should i add a new line(after line 84) or should i remove it(line 84)
Changes:
added code for priority queue which accepts values as per given priority