Скачиваний:
20
Добавлен:
01.05.2014
Размер:
46.08 Кб
Скачать

1) Удаляет первое МАХ число.

struct sp { int inf;

struct sp *next;

} *F;

void func(void)

{ struct sp *T,*U;

int max;

if(F==NULL) return;

max=F->inf;

for(T=F->next;T!=NULL;T=T->next)

if(T->inf>max) max=T->inf;

if(F->inf==max)

{

T=F;

F=F->next;

}

else

for(T=F;T->next!=NULL;T=T->next)

{

U=T->next;

if(U->inf==max)

{

T->next=U->next;

break;

}

}

return;

}

2) Удаляет все МАХ числа.

struct sp { int inf;

struct sp *next;

} *F;

void func(void)

{ struct sp *T,*U;

int max;

if(F==NULL) return;

max=F->inf;

for(T=F->next;T!=NULL;T=T->next)

if(T->inf>max) max=T->inf;

while(F!=NULL)

{

T=F;

if(F->inf==max)

{

F=F->next;

}

else break;

}

if(F!=NULL)

{

T=F;

while(T->next!=NULL)

{

U=T->next;

if(U->inf==max)

{

T->next=U->next;

}

else

T=T->next;

}

}

return;

}

3) Удаляет все четные элементы.

struct sp { int inf;

struct sp *next;

} *F;

void func(void)

{ struct sp *T,*U;

if(F==NULL) return;

for(T=F->next;T!=NULL;T=T->next)

if(F->inf%2==0)

{

T=F;

F=F->next;

}

else

for(T=F;T->next!=NULL;T=T->next)

{

U=T->next;

if(U->inf%2==0)

{

T->next=U->next;

break;

}

}

return;

}

4) Удаляет все не четные элементы.

struct sp { int inf;

struct sp *next;

} *F;

void func(void)

{ struct sp *T,*U;

if(F==NULL) return;

for(T=F->next;T!=NULL;T=T->next)

if(F->inf%2!=0)

{

T=F;

F=F->next;

}

else

for(T=F;T->next!=NULL;T=T->next)

{

U=T->next;

if(U->inf%2!=0)

{

T->next=U->next;

break;

}

}

return;

}

6) Удаляет первый и последний не четный элемент.

struct sp { int inf;

struct sp *next;

} *F;

void func(void)

{ struct sp *T,*U,*T1;

if(F==NULL) return;

if(F->next==NULL) return;

for(T=F->next;T!=NULL;T=T->next)

{

if(F->inf%2!=0)

{

T=F;

F=F->next;

break;

}

else

for(T=F;T->next!=NULL;T=T->next)

{

U=T->next;

if(U->inf%2!=0)

{

T->next=U->next;

break;

}

}

break;

}

T=F;

while(T->next!=NULL)

{

U=T->next;

if(U->inf%2==0) T=T->next;

else

{

T1=T;

T=T->next;

}

}

U=T1->next;

T1->next=U->next;

return;

}

7) Переставить первое MIN число в конец.

struct sp { int inf;

struct sp *next;

} *F;

void func(void)

{ struct sp *T,*T1,*posl;

int min;

if(F==NULL) return;

if(F->next==NULL) return;

min=F->inf;

for(T=F->next;T!=NULL;T=T->next)

{

if(T->inf<min) min=T->inf;

if(T->next==NULL) posl=T;

}

if(F->inf==min)

{

posl->next=F;

F=F->next;

posl=posl->next;

posl->next=NULL;

}

else

{

T=F;

while(T->next!=posl)

{

T1=T->next;

if(T1->inf==min)

{

T->next=T1->next;

posl->next=T1;

posl=T1;

posl->next=NULL;

break;

}

else T=T->next;

}

}

return;

}

8) Переставить все MIN числа в конец.

struct sp { int inf;

struct sp *next;

} *F;

void func(void)

{ struct sp *T,*T1,*posl,*posl1;

int min;

if(F==NULL) return;

if(F->next==NULL) return;

min=F->inf;

for(T=F->next;T!=NULL;T=T->next)

{

if(T->inf<min) min=T->inf;

if(T->next==NULL) posl1=posl=T;

}

while(F!=posl)

if(F->inf==min)

{

posl1->next=F;

F=F->next;

posl1=posl1->next;

posl1->next=NULL;

}

else

break;

if(F!=posl)

{

T=F;

while(T->next!=posl)

{

T1=T->next;

if(T1->inf==min)

{

T->next=T1->next;

posl1->next=T1;

posl1=T1;

posl1->next=NULL;

}

else T=T->next;

}

}

return;

}

9) Удалить элемент равный сумме своих соседей.

struct sp { int inf;

struct sp *next;

} *F;

void func(void)

{ struct sp *T,*T1,*T2,*T3;

if(F==NULL) return;

if(F->next==NULL) return;

T=F->next;

if(T->inf==F->inf)

F->next=T->next;

T1=F;

while(1)

{

T2=T1->next;

if(T2==NULL) break;

T3=T2->next;

if(T3==NULL) break;

if(T1->inf+T3->inf==T2->inf)

T1->next=T2->next;

else

{

T1=T1->next;

if(T1==NULL) break;

}

}

for(T=F;T!=NULL;T=T->next)

if(T->next->next==NULL)

{

T1=T->next;

break;

}

if(T->inf==T1->inf)

T->next=NULL;

return;

}

5) Удаляет числа которые не входят в интервал [a,b]

struct sp { int inf;

struct sp *next;

} *F;

void func(void)

{ struct sp *T,*U;

int a,b;

if(F==NULL) return;

if(F->next==NULL) return;

for(T=F->next;T!=NULL;T=T->next)

if(F->inf<a||F->inf>b)

{

T=F;

F=F->next;

}

else

for(T=F;T->next!=NULL;T=T->next)

{

U=T->next;

if(U->inf<a||U->inf>b)

{

T->next=U->next;

break;

}

}

return;

}

Соседние файлы в папке Кориткие программы по работе со строками на C++