Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

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

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M92490382
  • Price:- $120

Guranteed 48 Hours Delivery, In Price:- $120

Have any Question?


Related Questions in C/C++

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As