Answered step by step
Verified Expert Solution
Question
1 Approved Answer
A vector is an Abstract Data Type ( ADT ) that offers the following functions: size ( ) empty ( ) at ( i )
A vector is an Abstract Data Type ADT that offers the following functions: size empty at i returns the element at index i set i e replaces the element at index with value e insert i e inserts value e at index i erase i removes the element at index i Other C STL containers are the following: list stack queue priorityqueue deque set map STL vector is a C container, which is a collection of elements. #include using std::vector vector myVector ; STL vector is similar to a C array with the following additions: uses indexing to access vector elements but checks if index is within the array index range. STL vectors can be dynamically resized to add or remove elements. STL destruction automatically invokes the destructor for each of the elements. Offers functions that operate on the entire vector not just elements like copying and comparing entire vectors, or inserting and erasing multiple elements. Methods: vector n : constructor. Creates a vector of n elements. An empty vector is created if no argument is present. size : returns the number of elements in the vector. Page empty : true if the vector is empty. resize n : resizes the vector so that it can hold n elements. reserve n : allocated storage space should be able to hold n elements. at i : returns a reference to the element at index i but also checks if index i is within the correct bounds of the vector. front : returns a reference to the first element of the vector. back : returns a reference to the last element of the vector. pushback e : adds a copy of element e at the end of the vector. popback : removes the last element of the vector. Use the C STL vector to solve the following two exercises: Devise a C program that uses each of the above methods for a vector of integers. Display the results after every method call. Implement bubble sort to sort the vector of integers. Given N decimal numbers, find the mean, maximum, minimum. Your program will first ask for N the number of integers in the list, which the user will input. Then the user will input N more numbers. Use vector to store the numbers. Submit the main program with comprehensive tests.
A vector is an Abstract Data Type ADT that offers the following functions: size
empty
at i returns the element at index i set i e replaces the element at index with value e insert i e inserts value e at index i erase i removes the element at index i
Other C STL containers are the following: list stack queue priorityqueue deque set map
STL vector is a C container, which is a collection of elements.
#include
using std::vector
vector myVector ;
STL vector is similar to a C array with the following additions:
uses indexing to access vector elements but checks if index is within the array
index range.
STL vectors can be dynamically resized to add or remove elements.
STL destruction automatically invokes the destructor for each of the elements.
Offers functions that operate on the entire vector not just elements like copying
and comparing entire vectors, or inserting and erasing multiple elements.
Methods: vector n : constructor. Creates a vector of n elements. An empty vector is
created if no argument is present. size : returns the number of elements in the vector.
Page
empty : true if the vector is empty.
resize n : resizes the vector so that it can hold n elements.
reserve n : allocated storage space should be able to hold n elements.
at i : returns a reference to the element at index i but also checks if index i is
within the correct bounds of the vector.
front : returns a reference to the first element of the vector.
back : returns a reference to the last element of the vector.
pushback e : adds a copy of element e at the end of the vector.
popback : removes the last element of the vector.
Use the C STL vector to solve the following two exercises:
Devise a C program that uses each of the above methods for a vector of
integers. Display the results after every method call.
Implement bubble sort to sort the vector of integers.
Given N decimal numbers, find the mean, maximum, minimum. Your program
will first ask for N the number of integers in the list, which the user will input.
Then the user will input N more numbers. Use vector to store the numbers.
Submit the main program with comprehensive tests.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started