Ask Question
28 November, 08:15

Suppose you have two nonempty stacks S and T and a deque D. Describe how to use D so that S contains all of the elements of T below all of its original elements. Write the code in C++.

+3
Answers (1)
  1. 28 November, 09:41
    0
    The C+ + solution is given below

    Explanation:

    #include

    #include

    #include

    using namespace std;

    int main () {

    deque d;

    stack S, T;

    for (int i=5; i>=1; i--) {

    S. push (i);

    }

    cout<";

    for (stack temp=S; ! temp. empty (); temp. pop ()) {

    cout<
    }

    for (int i=10; i>=6; i--) {

    T. push (i);

    }

    cout<
    for (stack temp=T; ! temp. empty (); temp. pop ()) {

    cout<
    }

    while (! S. empty ()) {

    int t=S. top ();

    S. pop ();

    d. push_front (t);

    }

    while (! T. empty ()) {

    int t=T. top ();

    T. pop ();

    d. push_front (t);

    }

    cout<
    for (int i=0; i
    cout<
    }

    cout<<"<-back"<
    while (! d. empty ()) {

    int t=d. front ();

    d. pop_front ();

    S. push (t);

    }

    cout<
    for (stack temp=S; ! temp. empty (); temp. pop ()) {

    cout<
    }

    return - 1;

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Suppose you have two nonempty stacks S and T and a deque D. Describe how to use D so that S contains all of the elements of T below all of ...” in 📘 Engineering if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers