Before seeing the solution make sure that you tried enough. Don’t paste the whole code, just find out the logic. If you stuck in trouble, just inform me on comment.
/**Bismillahir Rahmanir Rahim**/
#include <stdio.h>
int queue[20], front=0, rear, i, cndtn=0;
void q_insrt(int item)
{
if(rear == 19)
{
printf("Overflow\n");
cndtn = 1;
return;
}
else
{
rear++;
queue[rear] = item;
}
}
int main()
{
int n, item;
printf("Please, input your QUEUE size (less then 20)\n");
scanf("%d", &n);
rear = n-1;
printf("Insert %d item.\n", n);
for(i=0; i<n; i++) scanf("%d", &queue[i]);
while(1)
{
printf("Insert an Item.\n");
scanf("%d", &item);
q_insrt(item);
if(cndtn == 1) return 0;
for(i=front; i<=rear; i++)
printf("%d ", queue[i]);
printf("\n");
}
return 0;
}
0 comments:
Post a Comment
Note: only a member of this blog may post a comment.