Информатика и технология программирования


Вопросы без ответов



//------------------------------------------------------bk53-07.cpp


struct list
{
int val;
list *next,*pred;
};
//------------------------------------------------------- 1


int F1(list *p)
{ int n;
for (n=0; p!=NULL; p=p-&#62next, n++);
return(n);
}
//------------------------------------------------------- 2


list *F2(list *p h, int v)
{ struct list *q;
q = new list;
q-&#62val = v; q-&#62next = p h; p h = q;
return ph;
}
//------------------------------------------------------- 3


list *F3(list *p, int n)
{
for (; n!=0 &#38&#38 p!=NULL; n--, p=p-&#62next);
return p;
}
//------------------------------------------------------- 4


list *F4(list *p h, int v)
{ list *q ,*p;
q = new list;
q-&#62val = v; q-&#62next = NULL;
if (ph == NULL) return q;
for ( p=ph ; p -&#62next !=NULL; p = p-&#62next);
p -&#62next = q;
return ph;
}
//------------------------------------------------------- 5


list *F5(list *p h, int n)
{ list *q ,*pr,*p;
for ( p=ph,pr=NULL; n!=0 &#38&#38 p!=NULL; n--, pr=p, p =p-&#62next);
if (p==NULL) return ph;
if (pr==NULL) { q=ph; ph=ph-&#62next; }
else { q=p; pr-&#62next=p-&#62next; }
delete q;
return ph;
}
//------------------------------------------------------- 6


int F6(list *p)
{ int n; list *q;
if (p==NULL) return(0);
for (q = p, p = p-&#62next, n=1; p !=q; p=p-&#62next, n++);
return n;
}
//------------------------------------------------------- 7


list *F7(list *p, int v)
{ list *q;
q = new list;
q-&#62val = v; q-&#62next = q-&#62pred = q;
if (p == NULL) p = q;
else
{
q-&#62next = p; q-&#62pred = p-&#62pred;
p-&#62pred-&#62next = q; p-&#62pred = q; p=q;
}
return p;
}
//------------------------------------------------------- 8


list *F8(list *ph)
{ list *q, *tmp, **pp;
tmp = NULL;
while (ph !=NULL)
{
q = ph; ph = ph-&#62next;
for (pp = &#38tmp; *pp !=NULL &#38&#38 (*pp)-&#62val &#60 q-&#62val;
pp = &#38(*pp)-&#62next);



Начало  Назад  Вперед



Книжный магазин