Stuck & Queue procedures in C

Reply

Join Date: Nov 2006
Posts: 11
Reputation: sofianos is an unknown quantity at this point 
Solved Threads: 0
sofianos sofianos is offline Offline
Newbie Poster

Stuck & Queue procedures in C

 
0
  #1
May 12th, 2007
hi im making an exercise about two arrays. one is a working like a stuck (LIFO-Last in First Out)array and the second one like a queue (FIFO-First IN First Out). The problem is that im confused what to write in the case 3 and 4.....
Any additional help about compiler syntax errors would be nc.

Thanks in advance....


#include <stdio.h>
#include <stdlib.h>
#define N 10
#define N2 12

int push(int stuck[N],int head,int item,int flag,int N);
int pop(int stuck[N],int head,int item,int flag);
int engueue(int Q[N2],int rear,int item,int flag,int front,int N2);
int dequeue(int Q[N2],int front,int rear,int item,int flag);

int N,stuck[N],N2,Q[N2];

int main()
{
int sel,flag,item,head=0,front,rear;
do
{
do
printf("1.Push\n");
printf("2.Pop\n");
printf("3.Degueue\n");
printf("4.Enqueue\n");
printf("5.EXIT\n");
scanf("%d",&sel);
while (sel>0) && (sel<6);
switch (sel)
{
case 1:{
printf("Dwse to item\n");
scanf("&d",&item);
push(stuck,head,item,flag);
if (flag==0)
printf("Stoiva pliris\n");
}
case 2:{
pop(stuck,head,item,flag);
if (flag==0)
printf("Stoiva adia\n");
else
writeln("%d",item);
}
case 3:{
printf("Dwse to item\n");
scanf("&d",&item);
engueue(Q,rear,item,flag,front,N2);
if (flag==0)
printf("Oura pliris\n");
}
case 4:{
dequeue(Q,front,rear,item,flag);
if (flag==0)
printf("Oura adia\n");
else
writeln("%d",item);
}
}
}
while (sel!=5);
system("pause");
return 0;
}
int push(int stuck,int head,int item,int flag,int N)
{
if (head<(N-1))
{
head+=1;
stuck[head]=item;
flag=1;
}
else
flag=0;
return flag,head;
}
int pop(int stuck,int head,int item,int flag);
{
if (head>0)
{
item=stuck[head];
head-=1;
flag=1;
}
else
flag=0;
return item,flag,head;
}
int engueue(int Q,int rear,int item,int flag,int front,int N);
{
if (front==0)
front=1;
if (rear<=(N2-1))
{
rear+=1;
Q[rear]=item;
flag=1;
}
else
flag=0;
return flag;
}
int dequeue(int Q,int front,int rear,int item,int flag);
{
if (front!=0)
{
item=Q[front];
front+=1;
flag=1;
if(front>rear)
{
rear=0;
front=0;
}
}
else
flag=0;
return flag,item;
}
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 2,030
Reputation: Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of Aia has much to be proud of 
Solved Threads: 177
Aia's Avatar
Aia Aia is offline Offline
Postaholic

Re: Stuck & Queue procedures in C

 
0
  #2
May 12th, 2007
Originally Posted by sofianos View Post
im confused what to write in the case 3 and 4.....
I, also, would be confused with that kind of indenting and spacing of
your code. To start read here about proper tagging of the code you
post.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 1,580
Reputation: Infarction has a spectacular aura about Infarction has a spectacular aura about Infarction has a spectacular aura about 
Solved Threads: 52
Infarction's Avatar
Infarction Infarction is offline Offline
Battle Programmer

Re: Stuck & Queue procedures in C

 
0
  #3
May 12th, 2007
Ok, first, if you'd read the rules and guidelines, you'd have seen that you should post your code between [code] and [/code] tags. That preserves the indentation and adds line numbers to make it easer for us to read and refer to your code. Keep it in mind for next time

You've got several syntax errors, as you mentioned. Hopefully I can remember them from top down.
- Your use of N and N2 in function declarations is not allowed, since they are literal values (not variables). Also, declaring them on line 11 is not allowed for the same reason.
- Declaring the stack and queue as globals and then passing them around is somewhat silly.
- On line 18 you have a 'do' which looks out of place. I'm assuming it goes with the while on line 25, but you forgot the braces. Also, your logic in the while is backwards. You'll repeat the loop any time the user enters a value between 1 and 5. Also, you need to put parentheses around the entire condition.
- On lines 30 and 44, you have scanf("&d"... which should be scanf("%d"....
- On lines 40 and 54, you call a function writeln which isn't defined. You probably want printf and to put a "\n" at the end of your output string.
- On each of your function definitions, you have the first parameter as an int not an int[]. Also, as mentioned, you can't have N and N2 in the parameter lists.
- In push(), pop(), and dequeue(), you can only return 1 value. You need to use pointers if you want to change the value of a parameter.
- You need to initialize all of your variables before you read from them. As it is, most of them have random bits in them, and those values are not legal, especially when reading from arrays.
- at the end of each case block, you need to add a break; or else you'll execute the next block as well.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC