Grade 9 · 11 algorithmsCitește în română
One-dimensional arrays (vectors)Tablouri unidimensionale (vectori)
Every one-dimensional arrays (vectors) algorithm from the Romanian high school curriculum, with the idea explained, its complexity, examples and code you can edit and run right here.
- 11algorithms
- 8chapters
- 1grade
11 algorithms
0%
One-dimensional arrays (vectors)
Tablouri unidimensionale (vectori) · 11 algorithms
- Reading and printing an arrayCitirea și afișarea unui vectorAn array stores several values of the same type, accessed by index. We declare the array with a fixed maximum size and use positions 1..n. n and the…
- Removing the even elementsEliminarea elementelor pareInstead of deleting the even elements one by one (every deletion shifts the whole rest of the array), we make a single pass: k counts the elements…
- Inserting a value after every even elementInserarea unei valori după fiecare element parWe go through the array from the end to the beginning. When v[i] is even, we shift the elements after it one position to the right and put x at…
- Inserting an element at a positionInserarea unui element pe o pozițieTo put val at position poz, we make room: we shift the elements v[poz..n] one position to the right. Shifting starts from the end (from n down to…
- Reversing an arrayInversarea unui vectorWe swap the first element with the last, the second with the second to last, and so on: v[i] with v[n - i + 1]. We stop halfway (i <= n / 2); if we…
- The maximum and the positions where it appearsMaximul și pozițiile pe care apareUnlike a sequence read one value at a time, an array can be traversed several times: in the first pass we find the maximum, in the second we print…
- Circular shift to the rightPermutarea circulară la dreaptaEvery element moves one position to the right, and the last one goes to the first position. We save v[n], shift the rest from the end towards the…
- Circular shift to the leftPermutarea circulară la stângaEvery element moves one position to the left, and the first one goes to the last position. We save v[1] in a variable, shift the rest (v[i] = v[i +…
- Deleting the element at a positionȘtergerea elementului de pe o pozițieTo delete the element at position poz, we shift the elements after it one position to the left, from left to right (v[i] = v[i + 1]), then n…
- Sum of the elements on even and odd positionsSuma elementelor de pe pozițiile pare și impareMind the difference between the position (the index i) and the value (v[i]). Parity is checked here for the index: v[2], v[4], ... are on even…
- Checking a symmetric arrayVerificarea unui vector simetricAn array is symmetric (a palindrome) if v[i] = v[n - i + 1] for every i. We compare the pairs from both ends towards the middle and stop at the…