void delallxy(Sqlist *l,int x,int y)
{
int i=0;
int j=0;
while(i<l->length)
{
if(l->data[i]>=x && l->data[i]<=y)
j++;
else
l->data[i-j]=l->data[i];
i++;
}
l->length -= j;
}
void Del_Same(LinkList &L){
Node *p ,*q;
p = L->next;
if(p==NULL)
return;
while(p->next!=NULL){
q=p->next;
if(p->data==q->data){
p->next=q->next;
free(q);
}
else
p=p->next;
}
}
void Sort(SeqList *L)
{
int i=0,j=L->length-1;
int t;
while(i<j)
{
while(L->data[i]%2==1)
i++;
while(L->data[j]%2==0)
j--;
if(i<j)
{
t=L->data[i];
L->data[i]=L->data[j];
L->data[j]=t;
}
}
}
void DelXY(LinkList &L,int mink,int maxk)
{
LinkList p,q,s;
p=L->next;
while(p->data!=mink)
{
p=p->next;
}
q=p->next;
while(q->data!=maxk)
{
s=q;
q=q->next;
p->next=q;
free(s);
}
}
void delExcrescentValue(SeqList *S){
int flag = 0,val = S.elem[0];
for(int i = 1;i<=S.last;i++){
if(val != S.elem[i]){
val = S.elem[i];
flag += 1;
S.elem[flag] = val;
}
}
S.last = flag;
return;
}
(1)以一维数组作存储结构
void reverse(SeqList *L)
{
int t=0,j=L->length-1;
for(int i=0;i<L->length/2;i++)
{
t=L->data[i];
L->data[i]=L->data[j];
L->data[j]=t;
j--;
}
}
(2)以单链表作存储结构
void reverse(LinkList &L)
{
LinkList p,q;
p=L->next;
L->next=NULL;
while(p!=NULL)
{
q=p->next;
p->next=L->next;
L->next=p;
p=q;
}
}
void DeleteMax(LinkList &L,int *e)
{
LinkList p,q,s;
p=L->next;
q=p->next;
s=p;
while(q!=NULL)
{
if(p->data < q->data)
p=q;
q=q->next;
}
while(s->next!=p)
{
if(p==L->next)
s=L;
else
s=s->next;
}
*e=p->data;
s->next = p->next;
free(p);
}
void del(LinkList &zs)
{
Node *q, *p1, *p2;
q = s;
p1 = q->next;
p2 = p1->next;
while(p2 != s)
{
p2 = p2->next;
p1 = p1->next;
q = q->next;
}
q->next = p2;
delete(p1);
}
|