Solution to use dynamic array as the underlying data structure to hold the list contents. The array … - Sikademy
Author Image

Archangel Macsika

use dynamic array as the underlying data structure to hold the list contents. The array will hold integer data. Here are the functions that your program should offer ( options in MENU): 1. Insert an item Insert function will insert the value at the start of the list. Tell the user how many list elements are shifted to make room for new item. 2. Delete an item It will ask the user for the value, if the value is present, it will be deleted from the list and function displays how many items are shifted to delete the value 3. Print out the items in the list

The Answer to the Question
is below this banner.

Can't find a solution anywhere?

NEED A FAST ANSWER TO ANY QUESTION OR ASSIGNMENT?

Get the Answers Now!

You will get a detailed answer to your question or assignment in the shortest time possible.

Here's the Solution to this Question


#include <iostream> #include <vector> using namespace std; vector<int> vec; void insertItem(int item) { vec.insert(0, item); } void deleteItem(int item) { vec.delete(item); } void printVec() { for (int i : vec) { cout << i << " "; } cout << endl; } int main() { bool flag = true; while (flag) { cout << "1. insert an item" << endl << "2. delete an item" << endl << "3. print all items" << endl << "4. exit" << endl; int n; cin >> n; switch(n) { case 1: cin >> n; insertItem(n); break; case 2: cin >> n; deleteItem(n); break; case 3: printVec(); break; case 4: flag = false; } } return 0; }

Related Answers

Was this answer helpful?

Join our Community to stay in the know

Get updates for similar and other helpful Answers

Question ID: mtid-3-stid-44-sqid-1052-qpid-48