Ask Question
29 August, 01:09

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++.

+2
Answers (1)
  1. 29 August, 01:20
    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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers