Saturday, 12 March 2016

Procedure 6.14 (Delete Item From Queue)


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_dlte()
{
    if(front > rear)
    {
        printf("Overflow\n");
        cndtn = 1;
        return;
    }
    else front++;
}
int main()
{
    int n, dlt;
    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]);
    printf("You input :: ");
    for(i=front; i<=rear; i++)
            printf("%d  ", queue[i]);
        printf("\n");
    while(1)
    {
        printf("For Delete an Item input 1.\n");
        scanf("%d", &dlt);
        q_dlte();
        if(cndtn == 1) return 0;
        for(i=front; i<=rear; i++)
            printf("%d  ", queue[i]);
        printf("\n.........................\n");
    }
    return 0;
}

0 comments:

Post a Comment

Note: only a member of this blog may post a comment.