Question

Array List Operations For an array based list, (A) If the Length operation associated with an unsorted list returns 15, and w

Please do this in C++

Please do this in C++
0 0
Add a comment Improve this question Transcribed image text
Answer #1

A)

  1. 6
  2. 7
  3. 14
  4. 8

B)

  1. 6
  2. 7
  3. 14
  4. 8

C)

Code:

#include <iostream>

#include <list>

#include <iterator>

#include <cstdlib>

#include <ctime>

using namespace std;

//function for printing the elements in a list

void showlist(list <int> g)

{

                list <int> :: iterator it;

                for(it = g.begin(); it != g.end(); ++it)

                                cout << *it << "\t";

                cout << '\n';

}

int main()

{

                list <int> demolist1, demolist2;

srand(time(NULL));

                for (int i = 0; i < 15; ++i)

                {

    int k = rand()%50 + 1;

                                demolist1.push_back(k);

    demolist2.push_back(k);

                }

showlist(demolist1);

                cout << "Size before deletion = " << demolist1.size() << endl;

list<int>::iterator itr1 = demolist1.begin();

advance(itr1, 6);

demolist1.erase(itr1);

cout << "After deleting 7th item: \n ";

showlist(demolist1);

                cout << "Size after deletion = " << demolist1.size() << endl;

                cout << "\n\n\nSorted List: \n";

                demolist2.sort();

                showlist(demolist2);

                cout << "Size before deletion = " << demolist2.size() << endl;

list<int>::iterator itr2 = demolist2.begin();

advance(itr1, 6);

demolist2.erase(itr2);

cout << "After deleting 7th item:\n ";

showlist(demolist2);

                cout << "Size after deletion = " << demolist2.size() << endl;

                return 0;

}

Output:


13 43 26 11 30 Size before deletion = 15 After deleting 7th item: 43 26 11 30 Size after deletion = 14 1957 1957 37 37 74 74

Add a comment
Know the answer?
Add Answer to:
Please do this in C++ Please do this in C++ Array List Operations For an array...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++. Difficulty with quickSort function. Code will not run quickSort function. The code I'm having trouble...

    C++. Difficulty with quickSort function. Code will not run quickSort function. The code I'm having trouble with is in bold. -------------------------------------------------------------------------------------------------driverProgram.cpp #include #include #include #include #include "quickSort.cpp" using namespace std; int main() { const int MIN_SIZE = 4; //Array size const int SIZE = 25; int theArray[SIZE] = {11, 22, 33, 44, 55, 66, 77, 88, 99, 12, 13, 14, 15, 16, 17, 18, 19, 18, 19, 20, 21, 22, 23, 24, 25}; cout << "List of 25 items: ";...

  • Hi, it's C++ question. Only can use <iostream> and <fstream>libraries Please help me, thanks Question Description:...

    Hi, it's C++ question. Only can use <iostream> and <fstream>libraries Please help me, thanks Question Description: For this project you will write a program to: a) read-in the 10 first names from a file (the file is a priori given to have exactly 10 entries, of a maximum length of 8 letters each) into a 2-dimensional character array, b) output the names to the terminal with each one preceded by a number indicating its original order in the list, c)...

  • c++ please Given the following skeleton of an unsorted list class that uses an unsorted linked...

    c++ please Given the following skeleton of an unsorted list class that uses an unsorted linked list: template<class ItemType> struct NodeType {                 ItemType item;                 NodeType* next; }; template<class ItemType> class UList { public:                 UList(); // default constrctor                 UList(const UList &x); // we implement copy constructor with deep copy                 UList& operator = (UList &x); // equal sign operator with deep copy                 bool IsThere(ItemType item) const; // return true of false to indicate if item is...

  • **Please do it in C++*** The university roster will be stored using an array list (class...

    **Please do it in C++*** The university roster will be stored using an array list (class StudentList). StudentList works as a regular arrayList, but instead of being a template class, it can only hold Student objects. We design it this way because some operations of StudentList would not be applicable to other objects. The StudentList class has the following attributes: int size int length Student *list (pointer for dynamic array of students) Complete all the methods of studentList.h to be...

  • Assignment #2: List - Array Implementation Review pages 6-7 in "From Java to C++" notes. Due...

    Assignment #2: List - Array Implementation Review pages 6-7 in "From Java to C++" notes. Due Friday, February 9th, 2017 @ 11:59PM EST Directions Create a List object. Using the following definition (List.h file is also in the repository for your convenience) for a list, implement the member functions (methods) for the List class and store the implementation in a file called List.cpp. Use an array to implement the list. Write the client code (the main method and other non-class...

  • ch 6 ex 14 lists plus, c++ plus data structures, linked list understanding Problem: Use the...

    ch 6 ex 14 lists plus, c++ plus data structures, linked list understanding Problem: Use the linked lists contained in the array pictures in figure 6.19 (see pics) to amswer the following questions : please show some explanation / work so that i can grasp and retain this information Thank you so much for your time! 14. Use the linked lists contained in the array pictured in Figure 6.19 to answer the following questions: a. What elements are in the...

  • How do I write this in the c++ language? 1. (10 points) Write a program to...

    How do I write this in the c++ language? 1. (10 points) Write a program to implement Heapsort. The input should be an array of size at least 15. Have the user enter the values or you can specify your own array (unsorted). The output should be the final sorted array AND print out the values in the max heap (just the heap, NOT the full array) after each MAX-HEAPIFY (after BUILD- MAX-HEAP i.e. don't print output in BUILD-MAX-HEAP) in...

  • Please help!! (C++ PROGRAM) You will design an online contact list to keep track of names...

    Please help!! (C++ PROGRAM) You will design an online contact list to keep track of names and phone numbers. ยท         a. Define a class contactList that can store a name and up to 3 phone numbers (use an array for the phone numbers). Use constructors to automatically initialize the member variables. b.Add the following operations to your program: i. Add a new contact. Ask the user to enter the name and up to 3 phone numbers. ii. Delete a contact...

  • c++ please read all question edit the program to test different random sizes of the array and give me the time in a file will be like random size of the array and next to it the time it took for each...

    c++ please read all question edit the program to test different random sizes of the array and give me the time in a file will be like random size of the array and next to it the time it took for each size Im trying to do time analysis for Quick sort but i keep getting time = 0 also i want edit the program to test different random sizes of the array and give me the time in a...

  • All those points need to be in the code Project 3 Iterative Linear Search, Recursive Binary...

    All those points need to be in the code Project 3 Iterative Linear Search, Recursive Binary Search, and Recursive Selection Sort Class River describes river's name and its length in miles. It provides accessor methods (getters) for both variables, toString() method that returns String representation of the river, and method isLong() that returns true if river is above 30 miles long and returns false otherwise. Class CTRivers describes collection of CT rivers. It has no data, and it provides the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT