Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Queue and Stacks

Queue and Stacks

Scheduled Pinned Locked Moved C / C++ / MFC
c++data-structureshelpquestion
20 Posts 9 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    KOOOSHA
    wrote on last edited by
    #1

    a) A C++ program that implements the Stacks ADT. b) A C++ program that implements the Queue ADT using two stacks (make use of the Stacks ADT that you have implemented in a). can anyone help me with these?

    P T C B S 6 Replies Last reply
    0
    • K KOOOSHA

      a) A C++ program that implements the Stacks ADT. b) A C++ program that implements the Queue ADT using two stacks (make use of the Stacks ADT that you have implemented in a). can anyone help me with these?

      P Offline
      P Offline
      parichaybp
      wrote on last edited by
      #2

      Hi , I have sent u Queue implemented using linked list. hope it will be helpfull for u. #include struct node { int data; struct node *link; }; void insert_rear(struct node **,int); int delete_front(struct node **); void display(struct node *); int count(struct node **); main() { int size,k,ch,n; struct node *p; clrscr(); p=NULL; printf("Enter the max size of the queue : "); scanf("%d",&size); while(1) { printf("\n\n1 to insert item in the queue"); printf("\n2 to delete item in the queue"); printf("\n3 to display elements of the queue"); printf("\n4 to count number of elements in the queue"); printf("\n0 to exit : \n"); printf("\nEnter ur choice : "); scanf("%d",&ch); switch(ch) { case 1: if(count(&p)==size) { printf("\nQueue full\n"); break; } else { printf("enter the data to be inserted in the queue "); scanf("%d",&n); insert_rear(&p,n); printf("item %d inserted in queue",n); } break; case 2: if(count(&p)==0) { printf("queue empty"); break; } else { k=delete_front(&p); printf("deleted item from queue is %d",k); } break; case 3: printf("the values in the queue are\n"); display(p); break; case 4: printf("the total number of elements in the queue are %d",count(&p)); break; case 0: exit(0); default: printf("wrong choice"); } } } void insert_rear(struct node **q,int num) { struct node *temp,*r; temp=*q; if(temp==NULL) { temp=(struct node *)malloc(sizeof(struct node)); temp->data=num; temp->link=NULL; *q=temp; } else { while(temp->link!=NULL) temp=temp->link; r=(struct node *)malloc(sizeof(struct node)); r->data=num; r->link=NULL; temp->link=r; } } int delete_front(struct node **q) { int k; struct node *temp; temp=*q; k=temp->data; *q=temp->link; free(temp); return k; } void display(struct node *q) { while(q!=NULL) { printf("%d\t",q->data); q=q->link; } } int count(struct node **q) { int c=0; struct node *temp; temp=*q; while(temp!=NULL) { c++; temp=temp->link; } return c; }

      1 Reply Last reply
      0
      • K KOOOSHA

        a) A C++ program that implements the Stacks ADT. b) A C++ program that implements the Queue ADT using two stacks (make use of the Stacks ADT that you have implemented in a). can anyone help me with these?

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #3

        do your homework yourself X| :suss:

        1 Reply Last reply
        0
        • K KOOOSHA

          a) A C++ program that implements the Stacks ADT. b) A C++ program that implements the Queue ADT using two stacks (make use of the Stacks ADT that you have implemented in a). can anyone help me with these?

          C Offline
          C Offline
          Cedric Moonen
          wrote on last edited by
          #4

          KOOOSHA wrote:

          can anyone help me with these?

          Yes probably.

          T 1 Reply Last reply
          0
          • C Cedric Moonen

            KOOOSHA wrote:

            can anyone help me with these?

            Yes probably.

            T Offline
            T Offline
            toxcct
            wrote on last edited by
            #5

            i totally agree :rolleyes:

            1 Reply Last reply
            0
            • K KOOOSHA

              a) A C++ program that implements the Stacks ADT. b) A C++ program that implements the Queue ADT using two stacks (make use of the Stacks ADT that you have implemented in a). can anyone help me with these?

              B Offline
              B Offline
              Bob Stanneveld
              wrote on last edited by
              #6

              Money is the magic word here... Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

              E T 2 Replies Last reply
              0
              • B Bob Stanneveld

                Money is the magic word here... Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

                E Offline
                E Offline
                Eytukan
                wrote on last edited by
                #7

                :laugh:


                --[V]--

                1 Reply Last reply
                0
                • B Bob Stanneveld

                  Money is the magic word here... Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

                  T Offline
                  T Offline
                  toxcct
                  wrote on last edited by
                  #8

                  gimme gimme gimme :rolleyes:

                  B 1 Reply Last reply
                  0
                  • T toxcct

                    gimme gimme gimme :rolleyes:

                    B Offline
                    B Offline
                    Bob Stanneveld
                    wrote on last edited by
                    #9

                    I'll search Google for just a few dollars :-> Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

                    T 1 Reply Last reply
                    0
                    • B Bob Stanneveld

                      I'll search Google for just a few dollars :-> Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

                      T Offline
                      T Offline
                      toxcct
                      wrote on last edited by
                      #10

                      Bob Stanneveld wrote:

                      few dollars

                      gud enuf :-D d'you want my paypal account to send ? lol

                      B 1 Reply Last reply
                      0
                      • T toxcct

                        Bob Stanneveld wrote:

                        few dollars

                        gud enuf :-D d'you want my paypal account to send ? lol

                        B Offline
                        B Offline
                        Bob Stanneveld
                        wrote on last edited by
                        #11

                        :-D Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

                        1 Reply Last reply
                        0
                        • K KOOOSHA

                          a) A C++ program that implements the Stacks ADT. b) A C++ program that implements the Queue ADT using two stacks (make use of the Stacks ADT that you have implemented in a). can anyone help me with these?

                          S Offline
                          S Offline
                          Stephen Hewitt
                          wrote on last edited by
                          #12

                          Use std::queue and std::stack. Steve

                          T 1 Reply Last reply
                          0
                          • S Stephen Hewitt

                            Use std::queue and std::stack. Steve

                            T Offline
                            T Offline
                            toxcct
                            wrote on last edited by
                            #13

                            stephen, please don't help him for his homework... people asking for such too general questions and that can't do the job they've been assigned to don't deserve a good answer

                            S S 2 Replies Last reply
                            0
                            • T toxcct

                              stephen, please don't help him for his homework... people asking for such too general questions and that can't do the job they've been assigned to don't deserve a good answer

                              S Offline
                              S Offline
                              Sebastian Schneider
                              wrote on last edited by
                              #14

                              I didnt see Stephen do anything bad. He just referred him to the STL, and if the guy works it out from there, I believe that is OK. Even we need pointers to references some times. Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.

                              T 1 Reply Last reply
                              0
                              • S Sebastian Schneider

                                I didnt see Stephen do anything bad. He just referred him to the STL, and if the guy works it out from there, I believe that is OK. Even we need pointers to references some times. Cheers, Sebastian -- Contra vim mortem non est medicamen in hortem.

                                T Offline
                                T Offline
                                toxcct
                                wrote on last edited by
                                #15

                                yeah, i understand this point of view and i conccur somewhat. but what i also observe - sadly - is that many people (newly registered to codeproject) come there to ask for one to make one's homework :( they not only miss the point of what homeworks are beeing for (to learn and progress) but they ask their question a somewhat hurting way... i can used to newbies that don't know the site, don't know where to ask, and don't really know where to start with their assignment, but i can't used to those guys that tell you : "do this, so that, the program has to output/compute this or this datas"... hey, we're not paid to do one's job. we can only help or link someone to a possible/best way to solve a specific point. i've quoted this from Bjarne Stroustrup's FAQ yesterday : "Will you help me with my homework? No. Sorry. I don't do (other people's) homework. I get too many requests for help with homework and help with finding bugs in student programs to be able to find the time. Anyway, having a distant expert fix your programs is not the best way to learn. Try finding a local person with C++ experience that you can ask for guidance. A good mentor is the best help a student can have; maybe that's why they are not easy to find. Also, no, I will not suggest "a good project for a student to work on". My experience is that learning enough about a student and his/her course to know what level of difficulty is required and what kind of project is of interst takes time. To think of a good project is then non-trivial, and to explain exactly what the project is and how to approach it can take several messages and several hours. I just don't have that kind of time. Remember, these request come at least weekly. Finally, some students seem to have the idea that if I suggest a project, I am morally obliged to provide quite detailed help in its completion. " do you better understand why i reacted like that ?

                                K 1 Reply Last reply
                                0
                                • K KOOOSHA

                                  a) A C++ program that implements the Stacks ADT. b) A C++ program that implements the Queue ADT using two stacks (make use of the Stacks ADT that you have implemented in a). can anyone help me with these?

                                  D Offline
                                  D Offline
                                  David Crow
                                  wrote on last edited by
                                  #16

                                  KOOOSHA wrote:

                                  can anyone help me with these?

                                  Yes, exactly what is it that you need help with?


                                  "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                                  "There is no death, only a change of worlds." - Native American Proverb

                                  K 1 Reply Last reply
                                  0
                                  • D David Crow

                                    KOOOSHA wrote:

                                    can anyone help me with these?

                                    Yes, exactly what is it that you need help with?


                                    "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                                    "There is no death, only a change of worlds." - Native American Proverb

                                    K Offline
                                    K Offline
                                    KOOOSHA
                                    wrote on last edited by
                                    #17

                                    i hv a stack ADT program. I hv to use it to implement a queue.. considerin the FIFO and LIFO rules for both of the structures i hv no freakin idea how to put it together.... -- modified at 10:35 Thursday 6th April, 2006

                                    D 1 Reply Last reply
                                    0
                                    • T toxcct

                                      yeah, i understand this point of view and i conccur somewhat. but what i also observe - sadly - is that many people (newly registered to codeproject) come there to ask for one to make one's homework :( they not only miss the point of what homeworks are beeing for (to learn and progress) but they ask their question a somewhat hurting way... i can used to newbies that don't know the site, don't know where to ask, and don't really know where to start with their assignment, but i can't used to those guys that tell you : "do this, so that, the program has to output/compute this or this datas"... hey, we're not paid to do one's job. we can only help or link someone to a possible/best way to solve a specific point. i've quoted this from Bjarne Stroustrup's FAQ yesterday : "Will you help me with my homework? No. Sorry. I don't do (other people's) homework. I get too many requests for help with homework and help with finding bugs in student programs to be able to find the time. Anyway, having a distant expert fix your programs is not the best way to learn. Try finding a local person with C++ experience that you can ask for guidance. A good mentor is the best help a student can have; maybe that's why they are not easy to find. Also, no, I will not suggest "a good project for a student to work on". My experience is that learning enough about a student and his/her course to know what level of difficulty is required and what kind of project is of interst takes time. To think of a good project is then non-trivial, and to explain exactly what the project is and how to approach it can take several messages and several hours. I just don't have that kind of time. Remember, these request come at least weekly. Finally, some students seem to have the idea that if I suggest a project, I am morally obliged to provide quite detailed help in its completion. " do you better understand why i reacted like that ?

                                      K Offline
                                      K Offline
                                      KOOOSHA
                                      wrote on last edited by
                                      #18

                                      dude chilllll maaan... i didnt ask for the whole program.. thanx for the asnwer but i just asked for tips thats it... u dont hv to make a freakin conspiracy out of it..

                                      1 Reply Last reply
                                      0
                                      • K KOOOSHA

                                        i hv a stack ADT program. I hv to use it to implement a queue.. considerin the FIFO and LIFO rules for both of the structures i hv no freakin idea how to put it together.... -- modified at 10:35 Thursday 6th April, 2006

                                        D Offline
                                        D Offline
                                        David Crow
                                        wrote on last edited by
                                        #19

                                        KOOOSHA wrote:

                                        i hv a stack ADT program. I hv to use it to implement a queue..

                                        Not possible, technically. A queue is a FIFO data structure whereas a stack is a LIFO data structure. Since both of these are linked lists, however, it should be easy enough to implement. Consider:

                                        class list
                                        {
                                        // put things in here that are common to both data structures
                                        };

                                        class queue : public list
                                        {
                                        };

                                        class stack : public list
                                        {
                                        };


                                        "Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain

                                        "There is no death, only a change of worlds." - Native American Proverb

                                        1 Reply Last reply
                                        0
                                        • T toxcct

                                          stephen, please don't help him for his homework... people asking for such too general questions and that can't do the job they've been assigned to don't deserve a good answer

                                          S Offline
                                          S Offline
                                          Stephen Hewitt
                                          wrote on last edited by
                                          #20

                                          If the homework was to "implement" a stack or queue then I didn't do it, I pointed him at existing implementations. It's all very trendy at the CodeProject to harp on about homework, and I agree that you shouldn't do a students work for him: But you don't have to put him in "solitary confinement". I just pointed the dude in the right direction (or as I said, possibly the wrong direction if the alleged assignment was to implement it yourself). Steve

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups