Ask Question
27 January, 13:03

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. 27 January, 14:17
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers