I ask you to clarify these tasks, but not to bring them solutions. In the first task, it is not clear to me what is meant by "each time reducing by 1 the number of elements analyzed," and in the 2nd, this part is "their first entries."

Tasks:

  1. An array A of size N is given. Arrange it in ascending order by the sorting method with a simple choice: find the maximum element of the array and swap it with the last element; perform the described actions N - 1 time, each time reducing by 1 the number of analyzed elements and displaying the contents of the array.
  2. An integer array of size N is given. Remove all identical elements from the array, leaving their first entries.

    1 answer 1

    1. Here is a simple sorting algorithm. Looking through the entire array, we find the maximum element. Swap it with the last element of the array. The first stage of sorting has been done: now we have the maximum element in the last cell, which should be there as a result. So, in the last cell put what you need. Now do the same with the remaining elements, i.e. with items with indices from 0 to N -1. And so on, until the entire array is ordered.
    2. The occurrence of a value is a specific element of the array, a cell containing this value. Those. you must leave the first cells with a repeating value.
    • Regarding the second task: Source array: 1 3 4 1 1 Result: 1 3 4 (the first unit was left, the others were deleted) Approximately how does it look? - ArniLand
    • one
      @miki ... (continue yourself). In item 1, determine the toli "from 0 to N-2", the toli "from 1 to N-1", otherwise the error. (A very common error "+ -1") @ArniLand in task 2 you need to use some kind of structure (enough sets to track that such an element has already been encountered). If it was, delete it (or by moving the tail, if you work with an array "in place", or by non-copying, if you copy it into a new array). If you do not use an additional set, then for each next element you will have to look through the resulting array for duplication. Could clarify the text, if necessary. - alexlz
    • @alexlz, absolutely correct remark. If indexing starts from 0, then the first pass is from 0 to N-1, the second from 0 to N-2, etc. @ArniLand, it seems, is exactly the way it should be. - skegg