| # | Problem | Pass Rate (passed user / total user) |
|---|---|---|
| 11420 | Implement a vector 1 |
|
| 11462 | cppreference |
|
| 11677 | Implement a list 4 (back and remove) |
|
Description
Warning: You are not allowed to use:
1. any static variables
2. any variables which is not inside a function
3. malloc and free
The storage of the vector is handled automatically, being expanded and contracted as needed. Vectors usually occupy more space than static arrays, because more memory is allocated to handle future growth. This way a vector does not need to reallocate each time an element is inserted, but only when the additional memory is exhausted.
REQUIREMENTS:
Implement the push_back(), pop_back(), reserve() and destructor member functions of Vector classes.
Note:
If the value of size is equal to the value of capacity, and you need to change the value of capacity (reallocate memory) when you push_back a new element. The rule of increasing capacity is: new capacity = max(old capacity + 1, old capacity * 3).
The constructor of vector will not create an array (which means size and capacity is 0).
Input
here are five kinds of commands:
- pop_back: removes the last element
- push_back: adds an element to the end
- capacity: returns the number of elements that can be held in currently allocated storage
- size: returns the number of elements
- reserve: reserves storage (Increase the capacity of the container to a value that's equal to new capacity. If new capacity is greater than the current capacity, new storage is allocated, otherwise the method does nothing.)
Each commands is followed by a new line character ('\n').
Output
The output should consist of the current state of the vector.
Sample Input Download
Sample Output Download
Partial Judge Code
11420.cppPartial Judge Header
11420.hTags
Discuss
Description
You must follow the rules as below:
1. do not use any static variables
2. do not use any variables which is not inside a function
3. only new, operator new, delete and operator delete are allowed to allocate or deallocate memory
4. memory usage limit: 2048 byte
You are required to implement a list.
You have to enable C++11 in this problem. (e.g. "g++ -std=c++11 ...")
Input
The input consist of a number of operations. Each operations (push_back, remove and show) are separated by a newline character ('\n').
Operation push_back: following by a non-negative integer (insert value, 0<=insert value<20). Push a node at the end position with insert value.
Operation remove: following by a non-negative integer (remove value, 0<=insert value<20). Erase all nodes which data is equal to remove value.
Operation show: print the value of all nodes in the list. Print a whitespace character (' ') after printing the value of nodes. If the list is empty, do not print anything.
Output
Implement List (constructor, destructor, push_back and remove) and operator<<(std::ostream &os,const List &lst).