AceTheInterview
Jobs in Pune | Work better in teams | Socialize with friends | Submit Q&A | Tell a friend
Search site for 

Top 100 Interview Questions & Answers in a convenient and easy to read book!

“I bought this guide a few days ago to prepare for my interview with Oracle. Many of the questions they asked me were from this guide. I found this book absolutely great!”

– Ravi, California

Read more comments...

Interview Questions And Answers RSS Feed

Answers »

  1. Submitted By: najoepot — October 6, 2006
    -1 votes
      + -

    Its better to use nodes here - in this way you use what is called the dynamic data structure. This means the size of the structure grows at run time.

    Start by defining a pointer to node structure.
    each node has a data field and pointer field

  2. Submitted By: jobhunter — October 6, 2006
    +10 votes
      + -

    The question did not ask for a suggestion. It is definitely possible to implement 2 stacks using a single array. The array shud be visible to both stacks (and therefore be global, or shud provide equivalent effect). Also the stack tops shud be taken care of. one top will decrement everytime the push method is called and one would be incremented. As soon as s1.top==s2.top we shud throw an exception.

  3. Submitted By: Hariprasad — October 18, 2006
    +1 votes
      + -

    As stated that the array should grown towards one point.so when s[i]==s[j] then it should through an exception.If we will look care fully if u will just mention the delete option that is LIFO than the result data structure will be nothing but the double ended queue.

  4. Submitted By: Jim Stevens — November 13, 2006
    -1 votes
      + -

    Imagine the situation whereby the array is only two ‘items’ ( bytes ) long

    You may have:
    ——————
    One stack that will overflow at three pushes
    OR
    Two stacks that will overflow at three pushes IF either of them has zero bytes in them
    OR
    Two stacks that will overflow at two pushes IF either of them has at least one byte in them
    OR
    Two stacks that will overflow at one push IF either of them has at least two bytes in them

  5. Submitted By: Nasimudeen.A — March 30, 2007
    +18 votes
      + -

    #define M 100
    int Stack[M];
    int top1=-1,top2=M;
    //s determine which stack
    void push(int s,int n)
    {
    if(top1+1==top2)
    printf(”Stack is full”);
    else
    {
    if(s==1) //push into first stack
    {
    top1++;
    Stack[top1]=n;
    }
    else if(s==2) //push into second stack
    {
    top2–;
    Stack[top2]=n;
    }
    else
    {
    printf(”Invalid stack”);
    }
    }
    }

  6. Submitted By: shakti — October 16, 2007
    -4 votes
      + -

    Invalid stack

  7. Submitted By: DAS — March 11, 2008
    not yet rated
      + -

    Seems like you could denote a single array using separate rows to indicate your separate stacks. (i.e. - array1 [2][n]). Then, it would be an easy “swap” type program. Just a thought…

  8. Leave an Answer/Comment

    To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
    Click to hear an audio file of the anti-spam word

Our Sponsors
Our Sponsors
Contact Us | FAQ | Sitemap | Terms of Use | Privacy Policy | Tell a Friend

Copyright © 1999-2006 Jeeve Technologies LLC. All rights reserved.