Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

******************sequence4.h******************** // CONSTRUCTOR for the sequence class: // sequence( ) // Postcondition: The sequence has been initialized as an empty sequence. // // MODIFICATION MEMBER

image text in transcribed

******************sequence4.h********************

// CONSTRUCTOR for the sequence class:

// sequence( )

// Postcondition: The sequence has been initialized as an empty sequence.

//

// MODIFICATION MEMBER FUNCTIONS for the sequence class:

// void start( )

// Postcondition: The first item on the sequence becomes the current item

// (but if the sequence is empty, then there is no current item).

//

// void advance( )

// Precondition: is_item returns true.

// Postcondition: If the current item was already the last item in the

// sequence, then there is no longer any current item. Otherwise, the new

// current item is the item immediately after the original current item.

//

// void insert(const value_type& entry)

// Postcondition: A new copy of entry has been inserted in the sequence

// before the current item. If there was no current item, then the new entry

// has been inserted at the front of the sequence. In either case, the newly

// inserted item is now the current item of the sequence.

//

// void attach(const value_type& entry)

// Postcondition: A new copy of entry has been inserted in the sequence after

// the current item. If there was no current item, then the new entry has

// been attached to the end of the sequence. In either case, the newly

// inserted item is now the current item of the sequence.

//

// void remove_current( )

// Precondition: is_item returns true.

// Postcondition: The current item has been removed from the sequence, and the

// item after this (if there is one) is now the new current item.

//

// CONSTANT MEMBER FUNCTIONS for the sequence class:

// size_type size( ) const

// Postcondition: The return value is the number of items in the sequence.

//

// bool is_item( ) const

// Postcondition: A true return value indicates that there is a valid

// "current" item that may be retrieved by activating the current

// member function (listed below). A false return value indicates that

// there is no valid current item.

//

// value_type current( ) const

// Precondition: is_item( ) returns true.

// Postcondition: The item returned is the current item in the sequence.

//

// VALUE SEMANTICS for the sequence class:

// Assignments and the copy constructor may be used with sequence objects.

#ifndef _STACK_SEQUENCE_H_

#define _STACK_SEQUENCE_H_

#include // Provides size_t

#include

namespace stack_sequence_4{

template typename T>

class sequence{

public:

// TYPEDEFS and MEMBER CONSTANTS

typedef std::size_t size_type;

// CONSTRUCTOR

sequence( );

// MODIFICATION MEMBER FUNCTIONS

void start( );

void advance( );

void insert(const T& entry);

void attach(const T& entry);

void remove_current( );

// CONSTANT MEMBER FUNCTIONS

size_type size( ) const {return first.size()+second.size();}

bool is_item( ) const;

T current( ) const;

private:

std::stack first;

std::stack second;

};

}

#include "sequence4.template"

#endif

*******************sequence4.template*********************(Need to implement this template file)

#include // Provides size_t

namespace stack_sequence_4 { //Implement all the functions here }

--------Please implement the member functions from the header file using stack in the template file .

thank you

The goal of this assignment is to reinforce using stacks in C++ programs. Specifically, the assignment is to do The following problem. Use the STL stack class, sequence4.h, and sequence_exam4.cpp for this assignment. Here's a new idea for implementing the sequence class. Instead of the items being stored on a linked list, they will be stored using two stacks as private member variables with the following: 1. Imagine the two stacks glued together with their tops right next to each other. 2. The bottom of the first stack is the beginning of the sequence. 3. The elements of the sequence continue up to the top of the first stack 4. The next element of the sequence is then the top of the second stack. 5. And the elements of the sequence then continue down to the bottom of the second sequence (which is the end of the sequence) 6. If there is a current element, then that element is at the top of the second stack

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

Step: 3

blur-text-image

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

Database Management With Website Development Applications

Authors: Greg Riccardi

1st Edition

0201743876, 978-0201743876

More Books

Students also viewed these Databases questions