Answer to Question #240605 in C++ for jan

Question #240605

Consider the list of integers (4,5,6,7,8) and we are implementing this list using an Array.

Do the following operations on the given list in C++ language:

·        Add(9): Using Add() to add an element 9 between 6 and 7.

·        Next(): Using Next() to move current pointer 1 shift to the right.

·        Remove(): To remove an element 7.

·        Length(): To return size of the list.

·        find(7): traverse the array until 7 is located.


1
Expert's answer
2021-09-22T23:43:35-0400
#include <iostream>
#include <vector>
using namespace std;
  
int main()
{
   
    vector<int> v = { 4,5,6,7,8};
    auto it = v.insert(v.begin()+3, 9);
    cout << "The vector elements are: ";
    for (auto it = v.begin(); it != v.end(); ++it)
        cout << *it << " ";
        
    vector<int>::iterator it1;
 
    it = v.begin()+4;
    v.erase(it);
    cout<<endl;
    for (auto it = v.begin(); it != v.end(); ++it)
        cout << ' ' << *it;
  
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS