/***************************************** * Instructions * - Replace 'uwuserid' with your uWaterloo User ID * - Select the current calendar term and enter the year * - List students with whom you had discussions and who helped you * * uWaterloo User ID: uwuserid @uwaterloo.ca * Submitted for ECE 250 * Department of Electrical and Computer Engineering * University of Waterloo * Calender Term of Submission: (Winter|Spring|Fall) 201N * * By submitting this file, I affirm that * I am the author of all modifications to * the provided code. * * The following is a list of uWaterloo User IDs of those students * I had discussions with in preparing this project: * - * * The following is a list of uWaterloo User IDs of those students * who helped me with this project (describe their help; e.g., debugging): * - *****************************************/ /********************************************************** * YOU MUST MODIFY THIS FUNCTION IF YOU DID NOT IMPLEMENT * Single_list.h IN PROJECT 1. THIS REQUIRES YOU TO: * 1. Change which header file is is included. * 2. Change the type of the member variable 'list'. * 3. Update the ostream<< operator so that it prints * out the entries in your implementation. **********************************************************/ #ifndef LINKED_STACK_H #define LINKED_STACK_H #ifndef nullptr #define nullptr 0 #endif #include "ece250.h" #include "Single_list.h" #include "Exception.h" #include template class Linked_stack { private: static int const ARRAY_CAPACITY = 8; Single_list list; int itop; int stack_size; public: Linked_stack(); Linked_stack( Linked_stack const & ); ~Linked_stack(); bool empty() const; int size() const; int list_size() const; Type top() const; void swap( Linked_stack & ); Linked_stack &operator=( Linked_stack ); void push( Type const &obj ); Type pop(); // Friends template friend std::ostream &operator<<( std::ostream &, Linked_stack const & ); }; template Linked_stack::Linked_stack(): stack_size( 0 ) { // Empty constructor } template Linked_stack::Linked_stack( Linked_stack const &stack ): itop( stack.itop ), stack_size( stack.stack_size ) { // enter your implementation here } template Linked_stack::~Linked_stack() { // } template bool Linked_stack::empty() const { // enter your implementation here return true; } template int Linked_stack::size() const { // enter your implementation here return 0; } // Do not change this implementation template int Linked_stack::list_size() const { return list.size(); } template Type Linked_stack::top() const { // enter your implementation here return Type(); } template void Linked_stack::swap( Linked_stack &stack ) { std::swap( list, stack.list ); std::swap( stack_size, stack.stack_size ); std::swap( itop, stack.itop ); } template Linked_stack &Linked_stack::operator=( Linked_stack rhs ) { swap( rhs ); return *this; } template void Linked_stack::push( Type const &obj ) { // enter your implementation here } template Type Linked_stack::pop() { // enter your implementation here return Type(); } // You will be required to modify this function in order to accomodate // your implementation of a singly linked list in Project 1. template std::ostream &operator<<( std::ostream &out, Linked_stack const &stack ) { if ( stack.list.size() == 0 ) { out << "->0"; } else if ( stack.list.size() == 1 ) { out << "->[ "; for ( int i = 0; i <= stack.itop; ++i ) { out << stack.list.front()[i] << " "; } out << "]->0"; } else { out << "->"; for ( Single_node *ptr = stack.list.head(); ptr != nullptr; ptr = ptr->next() ) { out << "[ "; if ( ptr == stack.list.head() ) { for ( int i = 0; i <= stack.itop; ++i ) { out << ptr->retrieve()[i] << " "; } } else { for ( int i = 0; i <= Linked_stack::ARRAY_CAPACITY - 1; ++i ) { out << ptr->retrieve()[i] << " "; } } out << "]->"; } out << "0"; } return out; } // Is an error showing up in ece250.h or elsewhere? // Did you forget a closing '}' ? #endif