Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
OAIP-_zadachi_shrift_5.doc
Скачиваний:
35
Добавлен:
11.05.2015
Размер:
178.69 Кб
Скачать

Int main(int argc, char* argv[])

{ int i, n, inf; ochd *spk, *spt, *st;

sp=spk=NULL;

for (i=0; i<5; i++)

{ cout << "Vvedite element " << i+1 << ": ";

cin >> inf; addochd(&sp, &spk, inf); }

spt=st=sp; n=st->inf;

while (st->a!=NULL)

{ if (st->a->inf>n)

{spt=st; n=st->a->inf; }

st=st->a; }

if (sp->inf==n)

{ spt=sp; sp=sp->a; delete spt; }

else delmax(&sp, &spk, &spt);

delochd(&sp, &spk); getch();

return 0; }

void addochd(ochd **sp,ochd **spk, int inf)

{ ochd *spt=new ochd; spt->inf=inf;

spt->a=NULL; if (*spk==NULL)

*sp=*spk=spt; else

{ (*spk)->a=spt; *spk=spt; } }

void delochd(ochd **sp,ochd **spk)

{ int inf; ochd *spt;

while (*sp!=NULL)

{ inf=(*sp)->inf; cout << inf << " ";

spt=*sp; *sp=(*sp)->a; delete spt; }

cout << endl; }

void delmax(ochd **sp, ochd **spk, ochd **spt)

{ ochd *st;

if ((*spt)->a->a==NULL)

{ st=(*spt)->a; (*spt)->a=NULL; delete st; }

else { st=(*spt)->a; (*spt)->a=(*spt)->a->a;

delete st; }}

Написать прогу формирующую однонаправленую очередь из 5 чисел. Добавить элемент после MIN элемента очереди.

Предусмотреть вывод результата и очистку очереди в конце работы.

#include <conio.h>

#include <iostream.h>

struct ochd

{ int inf; ochd *a; } *sp;

void addochd(ochd **, ochd **, int);

void delochd(ochd **, ochd **);

void dobel(ochd **, ochd **, ochd**);

Int main(int argc, char* argv[])

{ int i, n, inf; ochd *spk, *spt, *st;

sp=spk=NULL;

for (i=0; i<5; i++)

{ cout << "Vvedite element " << i+1 << ": ";

cin >> inf; addochd(&sp, &spk, inf); }

spt=st=sp; n=sp->inf;

while (st!=NULL)

{ if (st->inf<n)

{ spt=st; n=st->inf; }

st=st->a; } dobel(&sp, &spk, &spt);

delochd(&sp, &spk); getch(); return 0; }

void addochd(ochd **sp,ochd **spk, int inf)

{ ochd *spt=new ochd; spt->inf=inf; spt->a=NULL;

if (*spk==NULL) *sp=*spk=spt;

else { (*spk)->a=spt; *spk=spt; } }

void delochd(ochd **sp,ochd **spk)

{ int inf; ochd *spt;

while (*sp!=NULL)

{ inf=(*sp)->inf; cout << inf << " "; spt=*sp;

*sp=(*sp)->a; delete spt;} cout << endl; }

void dobel(ochd **sp, ochd **spk, ochd **spt)

{ int inf; ochd *st=new ochd; cout << "Vvedite chislo: ";

cin >> inf;

if ((*spt)->a==NULL)

{ (*spt)->a=st; st->a=NULL; st->inf=inf; }

else { st->a=(*spt)->a; st->inf=inf; (*spt)->a=st; } }

Пять элементов стека. Удалить чётные из них.

#include <conio.h>

#include <iostream.h>

struct stk

{ int inf; stk *a; } st;

stk *adst(stk *, int);

stk *delall(stk *);

stk *dell(stk *);

Int main(int argc, char* argv[])

{ int i, inf, n=5; stk *st=NULL;

for (i=0; i<n; i++)

{ cout << "Vvedite element " << i+1 << ": ";

cin >> inf; st=adst(st, inf); }

st=dell(st); delall(st); getch();

return 0; }

stk *adst(stk *st, int inf)

{ stk *spt=new stk; spt->inf=inf;

spt->a=st; return spt; }

stk *delall(stk *st)

{ int inf; stk *spt;

while (st!=NULL)

{ spt=st; st=st->a; inf=spt->inf;

cout << inf << " "; delete spt; }

cout << endl; return NULL; }

stk *dell(stk *st) { stk *spt;

while (st->inf%2==0&&st->a!=NULL)

{ spt=st; st=st->a; delete spt; }

if (st->a==NULL)

if (st->inf%2==0) return NULL;

else return st; spt=st;

while (spt!=NULL)

{ if (spt->a->a==NULL)

if (spt->a->inf%2==0)

{ spt->a=NULL; return st; }

else return st; if (spt->a->inf%2==0)

spt->a=spt->a->a; else spt=spt->a; }

return st; }

#include <conio.h>

#include <iostream.h>

#include <stdlib.h>

#include <stdio.h>

FILE *fl;

char a[9];

void vvod();

void rez();

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]