how to search all the content of stack

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kirubel dereje
    New Member
    • Dec 2011
    • 3

    how to search all the content of stack

    hi guys i am trying to build some program that need a stack and queue implementation i am using <stack.h> and <queue.h>
    and i want to search the contents without removing elements completely is there some built in function or some sort of method to do this.
    thanks a lot.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    The usual methos for searching a stack is to pop from the stack and pus onto a temporary stack.

    Ditto for a queue.

    The nature of these data structures is t allow access only to the top object in the stack and the front object in the queue.

    Going up and down the data searching is done using a list and not a stack or a queue.

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      I don't recognize stack.h or queue.h. Are these standard Library headers? If not, where did they come from and are you sure you're using the related functions properly?

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        stack.h and queue.h are 1998 or earlier pre-ANSI C++ headers. Using them them says the OP has a very old compiler.

        Comment

        • kirubel dereje
          New Member
          • Dec 2011
          • 3

          #5
          yes they are built in header files if you use them they save a lots of time and coding.what you need is include this headers and use this syntax for beginning.
          #include<stack. h>
          #include<queue. h>
          int main()
          {
          stack<char> s;
          queue<char> q;
          char content;
          s.push(content) ;/* add elements */
          q.push(content) ;
          s.pop();/* remove elements */
          q.pop();
          return 0;
          }

          Comment

          • kirubel dereje
            New Member
            • Dec 2011
            • 3

            #6
            so if you got some method please inform me thanks.

            Comment

            • weaknessforcats
              Recognized Expert Expert
              • Mar 2007
              • 9214

              #7
              Did you read my Post #2?

              Comment

              Working...