Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

sailakshmi17
Copy link
Contributor

Changes:

added code for priority queue which accepts values as per given priority

@arnavb
Copy link
Member

arnavb commented Oct 15, 2018

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;
Copy link
Member

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;
Copy link
Member

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) {\
Copy link
Member

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?

Copy link
Contributor Author

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;
Copy link
Member

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;
Copy link
Member

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++)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preincrement.

Copy link
Contributor Author

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++)
{
Copy link
Member

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");

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra newline.

Copy link
Contributor Author

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants