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.....:?:

``````#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()
{
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);
if (flag==0)
printf("Stoiva pliris\n");
}
case 2:{
if (flag==0)
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)
else
writeln("%d",item);
}
}
}
while (sel!=5);
system("pause");
return 0;
}
int push(int stuck,int head,int item,int flag,int N)
{
{
flag=1;
}
else
flag=0;
}
int pop(int stuck,int head,int item,int flag);
{
{
flag=1;
}
else
flag=0;
}
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;
}
``````

Edited by pyTony: fixed formatting

3
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by Infarction

im confused what to write in the case 3 and 4.....

I, also, would be confused with that kind of indenting and spacing of
post.

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 :icon_wink:

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.