#include <iostream>#include<cstring>#include<string>#include<queue>#include<map>#include<cstdio>using namespacestd;template<typename t>classsqlist{ Public: T data[ -]; intN; voidInitData (); voidDeletexone (T x); voiddeletextwo (T x); voidDeletexthree (T x); voidOutdata (); Private:};template<typename t>voidSqlist<t>:: Outdata () { for(intI=0; i<n; ++i) cout<<data[i]<<" "; cout<<Endl;} Template<typename t>voidSqlist<t>:: InitData () {cin>>N; for(intI=0; i<n; ++i) Cin>>data[i];} Template<typename t>voidSqlist<t>::d eletexone (T x) {intK =0; for(intI=0; i<n; ++i)if(Data[i]! = x)//if the current element is x, then the element is ignoreddata[k++] =Data[i]; N=K; Outdata ();} Template<typename t>voidSqlist<t>::d eletextwo (T x) {intK =0;//record the number of vacancies for(intI=0; i<n; ++i) { if(data[i]==x)++K; ElseData[i-K] = data[i];//move the K position forward} n= NK; Outdata ();} Template<typename t>voidSqlist<t>::d eletexthree (T x) {intI=0, j=n-1, k=0; while(I < J) {//constantly moving the element to the right of data to the left of data is the position of the element x. while(data[i]!=x && i<j) + +i; while(Data[j]==x && i<j)--J; if(I>=J) Break; Data[i]=Data[j]; ++K; } N= NK; Outdata ();}intMain () {sqlist<int>sq; Sq.initdata (); Sq.deletexone (2); Sq.deletextwo (0); Sq.deletexthree (4); return 0;}/*101 2 0 3 4 6 8 5 9 7*/
Data Structure Review Order table 3 How to delete elements (did you build it)