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 |