Thread: can you help me in this

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    12

    Unhappy can you help me in this

    hello every one i hope you doing will

    so my problem is there
    check the code and help me
    Code:
    #include<stdio.h>
    #include<conio.h>
    #define max 5
    struct queue
    {
            int front,rear,q[max];
    };
    void enqueue(struct queue*);
    void dequeue(struct queue*);
    void qdisplay(struct queue*);
    void main(void)
    {
             int c;
             struct queue q;
             q.front=q.rear=-1;
             do
             {
                     printf("1:insert\n2:deletion\n3:display\n4:exit\nenter choice:");
                     scanf("%d",&c);
                     switch(c)
                             {
                                     case 1:enqueue(&q);break;
                                     case 2:dequeue(&q);break;
                                     case 3:qdisplay(&q);break;
                                     case 4:printf("pgm ends\n");break;
                                     default:printf("wrong choice\n");break;
                             }
             }while(c!=4);
             getch();
    }
    void enqueue(struct queue *p1)
    {
             int x;
             if((p1->front==0&&p1->rear==max-1)||(p1->front==p1->rear+1))
    C program to implement circular Queue using Structure       {
                     printf("q is overflow\n");return;
             }
             if(p1->front==-1)
             {
                     p1->front=p1->rear=0;
             }
             else
             {
                     if(p1->rear==max-1)
                     {
                             p1->rear=0;
                     }
                     else
                     {
                             p1->rear++;
                     }
             }
             printf("enter the no:\n");
             scanf("%d",&x);
             p1->q[p1->rear]=x;
             printf("%d succ. inserted\n",x);
             return;
    }
    void dequeue(struct queue *p2)
    {
             int y;
             if(p2->front==-1)
             {
                     printf("q is underflow\n");return;
             }
             y=p2->q[p2->front];
             if(p2->front==p2->rear)
             {
                     p2->front=p2->rear=-1;
             }
             else
             {
                     if(p2->front==max-1)
                     {
                             p2->front=0;
                     }
                     else
                     {
                             p2->front++;
                     }
             }
             printf("%d succ. deleted\n",y);
             return;
    }
    void qdisplay(struct queue *p3)
    {
             int i,j;
             if(p3->front==p3->rear==-1)
             {
                     printf("q is empty\n");return;
             }
             printf("elements are :\n");
             for(i=p3->front;i!=p3->rear;i=(i+1)%max)
             {
                     printf("%d\n",p3->q[i]);
             }
             printf("%d\n",p3->q[p3->rear]);
             return;
    }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What's the problem?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Mar 2013
    Posts
    12
    try to execute the program

  4. #4
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by MARCELO View Post
    try to execute the program
    Do you really think that I run a program that doesn't even compile ?
    Kurt

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by MARCELO
    try to execute the program
    That is another way of saying: debug this program for me.

    So, no. You compile and try to execute your program, then post the actual program that you compiled and ran, and tell us exactly what is the problem and what you expected it to do.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User
    Join Date
    Mar 2008
    Posts
    82
    Thanks for asking to check 99 lines of code, especially because I have a fast way of checking code with ONE glance, because I check for comments, that is lines with // or /* */
    and in your case the code is really simple, it has the value of ZERO comments.

    No helpful comments means unfriendly code. They are used, for example, to say, what a function will do and what its order might be in the program flow.

    Don't accuse me of being a cheat, because I did check for one thing and I was lucky that its value was zero, so I was finished extremely quickly.
    Last edited by stabu; 04-12-2013 at 03:24 AM.

  7. #7
    Registered User
    Join Date
    Mar 2013
    Posts
    12
    im asking to help i thing this is question not explaining so every one can edit the code and send it to me i will be thanx full for him

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by MARCELO
    im asking to help i thing this is question not explaining so every one can edit the code and send it to me i will be thanx full for him
    You didn't tell us what the code is supposed to do and how does it not work, and now you are telling us, in broken English, that we can edit the code and send it to you?

    There is a link in my signature about asking smart questions. Read it.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    spaghetticode
    Guest
    Quote Originally Posted by laserlight View Post
    There is a link in my signature about asking smart questions. Read it.
    Double benefit here: Reading might not only improve your manner of asking questions, but also your English. (No, that's not meant as an offense.)

  10. #10
    Registered User
    Join Date
    Mar 2013
    Posts
    12
    i know my English language so bad i'm a sudanese so i'm sorry
    i will do my work with myself sorry again good luck

  11. #11
    spaghetticode
    Guest
    Quote Originally Posted by MARCELO View Post
    i know my English language so bad i'm a sudanese so i'm sorry
    i will do my work with myself sorry again good luck
    Nothing to be sorry about. As long as you follow the given advice, everything is fine. :-)

  12. #12
    Registered User
    Join Date
    Mar 2013
    Posts
    12
    thank you for that ^_^

  13. #13
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Sigh...just another copy/paste job.

Popular pages Recent additions subscribe to a feed