SWUST数据结构--顺序表中重复数据的删除

xiaoxiao2021-02-28  27

#include<iostream> #include<cstdlib> using namespace std; typedef struct { int data[100]; int length; }list; void Init(list *&L) { L=(list *)malloc(sizeof(list)); L->length = 0; } void Creat(list *&L) { int i,n; cin>>n; L->length = n; for(i=0;i<n;i++) { cin>>L->data[i]; } } void Dele(list *&A,list *&B,int e) { int i,j=0; for(i=0;i<A->length;i++) { if(A->data[i] != e) B->data[j++] = A->data[i]; } B->length = j; } void Disp(list *&L) { int i; for(i=0;i<L->length;i++) { cout<<L->data[i]<<' '; } } int main() { list *A,*B; int e; Init(A); Init(B); Creat(A); cin>>e; Dele(A,B,e); if(B->length == 0) cout<<"-1"; else Disp(B); return 0; }
转载请注明原文地址: https://www.6miu.com/read-2649970.html

最新回复(0)