【有序数组去重】2022-11-25
缘由删去数组中重复的数字-编程语言-CSDN问答
template <class 形参>
void 有序数组去重(形参* a, int n)
{//缘由https://ask.csdn.net/questions/7845471int x = 0, j = 0;qc:if (++x < n){if (a[x - 1] == a[x]){j = x;jc:if (++j < n)if (a[x] == a[j]) goto jc;if (j < n){a[x] = a[j];fg:if (--j > x){ a[j] = a[x]; goto fg; }}else x = n;j = 0;//观察运行过程sc:if (j < n){std::cout << a[j], ++j;goto sc;}std::cout << "\n";}goto qc;}
}int a[]{0, 1, 4, 7, 8, 5, 2, 3, 6, 9, 8, 5, 2}, n = 13, b = 0;折扇排序(a, n);有序数组去重(a, n);sc:if (++b < n){if (a[b - 1] != a[b])std::cout << a[b - 1];elsestd::cout << a[b], b = n - 1;goto sc; }std::cout << "\n";