Write a stack class using two stl lists

Assignment Help C/C++ Programming
Reference no: EM131681682

Question 1. You are given two STL lists X and P where P is already in sorted order. Write a valid C++ function printPositions(X, P ) that prints the elements in X specified by P . For example, if P = 0, 2, 5, 6, the elements in positions 0 (head of the list), 2, 5, and 6 in X are printed. You may use only the public STL container operations. Also specify the running time of your algorithm using Big-Oh notation.

Hint: You may wish to use iterators while keeping track of the position of items being iterated through.

Question 2. Given two unsorted STL lists X and P , write a valid C++ function intersection(X, P ) that returns a new list that contains the elements common to both X and P . For example, if X = 5, 2, 1, 4 and P = 4, 5, 7; your algorithm should return a new list containing 5 and 4 (order is not important). Also specify the running time of your algorithm using Big-Oh notation. Hint: As the lists are unsorted, a straightforward algorithm would need a double for loop.

Question 3. For the Vector class available on Blackboard, add an iterator insert(iterator pos, const Object & x) method. Note to move the iterators (which are really just pointers here) around, you need to add to them sizeOf(Object). For example, pos += sizeOf(Object); lets you examine the next item in the Object array.

Question 4. Verbally describe how two different stacks can be implemented using a single array.

Question 5. Write a stack class using two STL lists. Naturally, a single STL list is more than enough to represent a stack. However, you are only limited to the following STL list methods:

(a) void push back(const Object & x); //adds x to the end of list (b)void pop front(); //removes the object at the front of the list (c)Object & front(); //returns the object at the front of the list (d)bool empty() const; //true if empty container

Limited to these methods alone, our STL list essentially becomes a queue (enqueue is basically push back while dequeue is a combination of front and pop front). At the minimum, your stack class needs to have the following:

(a) An STL list is stored as an instance member of the stack class. You can think of this main list as storing your stack.

(b) A pop method that returns an Object at the top of the stack.

(c) A push method that takes an Object and places it at the top of the stack.

(d) If your list is empty, your pop method should throw an exception (any exception will do).

(e) Inside your push method, you can create a temporary list. As you are only limited to placing items at the back of your list (enqueue / push back), you can use this temporary list as storage to help move items from your main list to this list, add the new item to your main list, and then move back the items from the temporary list back to your main list.

Attachment:- Vector.rar

Reference no: EM131681682

Questions Cloud

Calculate the erp total cost of ownership : Calculate the ERP's total cost of ownership (TCO). The cost of the ERP or the monthly SaaS fee is only the beginning of the calculation.
Describe the leadership style or traits : Is the Wal-Mart top Management effectively leading the company? Describe the leadership style or traits that you utilized to be a successful leader.
Fund board of directors proposed : Concerned, the fund's board of directors proposed to cap the fund manager's compensation to $200K. Provide arguments in favor and against the proposal.
Write a paper about are men and women treated equally now : Write a Paper about Are men and women treated equally now? Find a news article that supports an answer to the question you chose.
Write a stack class using two stl lists : CSC 2200 - Write a stack class using two STL lists. Naturally, a single STL list is more than enough to represent a stack and Object at the top of the stack
Solow-swan growth framework : Explain the intuition behind your answer using the Solow-Swan growth framework.
Define the rule of law as described by professor dicey : Critically evaluate the effectiveness and the application of the notions, The Rule of Law as described by Professor Dicey
Policy options to stabilize the economy : There are several fiscal policy options to stabilize the economy: Changes in Government Purchases, Business Taxes, Income Taxes, and Transfer Payments.
Investigate a large company in a different industry : Each group should visit and investigate a large company in a different industry and identify its channel systems. Then find how IT supports.

Reviews

len1681682

10/16/2017 3:06:58 AM

5 questions. plus i will provide the "vector.h" for the questions that needs it • The submitted file have to be named as LastName FirstName HW1.pdf (e.g., Hailat Zeyad HW1.pdf). • This assignment needs to be typed as most of the questions are C++ coding. • Each question is worth 10 points for a total of 50 points. Show all of your work.

len1681682

10/16/2017 3:06:06 AM

Submission Instructions • Submit your homework as a single PDF document via Blackboard. • The submitted file have to be named as LastName FirstName HW1.pdf (e.g., Hailat Zeyad HW1.pdf). • This assignment needs to be typed as most of the questions are C++ coding. • Each question is worth 10 points for a total of 50 points. Show all of your work. CSC 2200

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd