Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write the function reverse0 in valid C+ code to reverse a linked list using a stack. You must use a list iterator to traverse the

image text in transcribed

Write the function reverse0 in valid C+ code to reverse a linked list using a stack. You must use a list iterator to traverse the linked list. Assume that the linked list is implemented by the class IntList with the following interface: class IntList ( private: struct Node { int data; Node next, Node* head; unsigned int size public class iterator ( int& operator O const iterator& operator++0 class const iterator const int& operator*O const; const iterator& operatort +O. W returns an iterator associated with the first element in the list iterator begin0; / returns an iterator associated with the last element in the list terator endO / returns the last clement in the list int pop back): W returns the first element in the list int pop front0 W adds x to the end of the list void push back(const int& x) W adds x to the beginning void push_front(const int& x): / returns the number of elements in the list of the list unsigned int sizeO: The stack is implemented by the class IntStack with the following interface class IntStack ( public: push x on the stack void push(const int & x); // pop the elementom the top of the stack and store in x void pop(int& x) I return true if the stack is empty bool isEmpty0; // peek the element at the top without popping it const int&top0: Your implementation of the function reverse0 should start as follows: void reverseo IntList input; //e.g. 5-> 2--> 7 IntList output; //e-g. 7 2--> 1 5 IntStack s IntListiterator it -input.beginO TODO: you code here

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

Students also viewed these Databases questions