Rudy’s OBTF Rudolf Adamkovič

Home / Computer science / Unordered remove


Example

/* Example of "unordered remove". */

#include <stdio.h>

int a[] = {30, 10, 20, 50, 40};
int n = sizeof(a) / sizeof(a[0]);

int main() {

  a[1] = a[n - 1]; // Move the last element.
  n--;             // Remove the last element.

  printf("index,value\n");
  for (int i = 0; i < n; i++)
    printf("%d, %d\n", i, a[i]);
}
index value
0 30
1 40
2 20
3 50

© 2025 Rudolf Adamkovič under GNU General Public License (GPL) version 3 or later.
Made with Emacs and secret alien technologies of yesteryear.