• Nie Znaleziono Wyników

push_back – adding a value to the vector (with memory allocation if necessary

N/A
N/A
Protected

Academic year: 2021

Share "push_back – adding a value to the vector (with memory allocation if necessary"

Copied!
1
0
0

Pełen tekst

(1)

1. Write a program which implements an unbounded vector container (using sequential memory storage) as a template structure (aimed at storing values of any type), and a set of methods operating on this structure:

• the default constructor (with some starting memory allocation),

• the destructor (with memory deallocation),

• the copy-constructor (with memory allocation),

• the assignment operator= (with memory dellocation and allocation),

• the comparison operator==,

• the indexing operator[],

• push_back – adding a value to the vector (with memory allocation if necessary),

• pop_back – removig the last value from the vector or throwing an empty vector exception,

• front – returning the first value or throwing an empty vector exception,

• back – returning the last value or throwing an empty vector exception,

• empty – informing whether the vector is empty,

• size – returning the number of items in the vector,

• clear – removing all the items from the vector.

The program should use all these methods to make the operations as follows:

1) create a vector of integers containing the numbers given by the user, 2) print the contents of the vector (with the help of the indexing operator), 3) remove the last value from the vector,

4) print the first and the last number,

5) print the number of values in the vector if it is nonempty, or an appropriate message otherwise,

6) clear the vector.

Compare your implementation of the container with the built-in container delivered in

<vector> library.

2. Implement an unbounded stack (using non-sequential memory storage – the linked list) as a template structure (aimed at storing values of any type), and a set of methods operating on this structure mentioned in the task of lab 5. Compare your implementation with the built-in structure delivered in <stack> library.

3. Write a program which checks whether in a string given by the user all parentheses, brackets and braces are balanced. For example, the following strings contain balanced parentheses:

([]())

([])([]{}{()}[])

Examples of imbalanced ones are:

([)]

([])([]{}{())}[])

To solve the problem use one of the structures implemented in task 1 or 2.

Cytaty

Powiązane dokumenty

Write a program which implements a bounded stack (a Last-In-First-Out structure using sequential memory storage), aimed at storing real numbers, and a set of methods operating on

Write a program which implements an unbounded queue (a First-In-First-Out structure using sequential memory storage), aimed at storing real numbers, and a set of methods operating

The torsion of the null vector field on M relative to the affine connection T equals to the torsion tensor of the linear connection T whose extension by the canonical form is

Furthermore, the Internet is an equally effective channel in familiar- izing the younger generations of Palestinians with their tradition, culture and heritage through the

ANNALES SOCIETATIS MATHEMAT1CAE POLONAE Series I: COMMENTATIONES MATHEMATICAE XX!V (1984) ROCZNIK1 POLSK1EGO TOWARZYSTWA MATEMATYCZNEGOH. Séria I: PRACE MATEMATYCZNE

In [1] it was used in proving that every infinite-dimensional Fréchet space, non-isomorphic to со, admits a strictly weaker complete locally convex topology with the

I t has come into existence thanks to Professor Olech’s valuable directions and aid... We shall call the function/a density

naturalne masy kłębów dochodzące do 10% oraz ubytki naturalne skrobi przekraczające 10% w stosunku do ilości skrobi stwierdzonej przy kop- cowaniu. Trzeba tu jeszcze dodać, że