Documente Academic
Documente Profesional
Documente Cultură
CATEDRA: Tehnologii
Informaionale
ELABORAT:
Studentul gr TI-122
Suiu Ion
VERIFICAT:
Profesorul
Sirbu Tamara
Chiinu 2013
SCOPUL LUCRRII:
Studierea algoritmilor de cutare n graf i a diferitor forme de pstrare i prelucrare a datelor.
Elaborarea procedurii de cutare n adncime si largime
SARCINA DE BAZ
1.
int getst(stiva s)
{
if (!s) return -1;
else return(s->ai);
}
int mdfcontine(lista *cap,int n,int t[])
{
while (cap)
if (este(cap->inf,n,t))
cap=cap->next;
else return(cap->inf);
return (-1);
}
void Drumul_Init()
{
int i;
for (i=0;i<15;i++)
tab[i]=-999;
}
void InitTL()
{
int i;
for (i=0;i<15;i++)
tl[i]=NULL;
}
void IntrTL()
{
int v;
printf("n=");
scanf("%d",&n);
for (i=1;i<=n;i++)
{
printf("%d->",i);
do
{
scanf("%d",&v);
tl[i]=inss(tl[i],v);
} while(v!=0);
}
}
void AfisTL()
{
for (i=1;i<=n;i++)
{
printf("%d-> ",i);
afisl(tl[i]);
puts("");
}
}
void Parc_adn()
{
int v1,vc,k;
m1:printf("Introdu primul virf ");
scanf("%d",&v1);
if(v1<1 || v1>n)
{
puts("Virf inexistent!");
getch();
goto m1;
}
else
{
tab[j++]=v1;
s=ps(s,v1);
}
int b=1;
while (b)
{
while (s)
{
vc=getst(s);
if (tl[vc] && tl[vc]->inf!=0)
{
int c=mdfcontine(tl[vc],j-1,tab);
if (c!=-1 && c)
{
tab[j++]=c;
s=ps(s,c);
}
else s=pop(s,&k);
}
else s=pop(s,&k);
}
b=0;s=NULL;
for (i=1;i<=n;i++)
if (!este(i,j-1,tab))
{
b=1;tab[j++]=i;
s=ps(s,i);
break;
}
}
}
void AfisDrum()
{
for (i=0;i<j;i++)
printf("%d ",tab[i]);
}
int menu()
{
clrscr();
int func=1;
while (1)
{
gotoxy(23,12);
cputs("-------------------------------------------------------------------------------");
gotoxy(23,13);
cputs("");
cputs("
MENIU
");
cputs("");
gotoxy(23,14);
cputs("-------------------------------------------------------------------------------");
gotoxy(23,15);
cputs("
");
gotoxy(23,16);
cputs("");
textbackground(4*(func==1));
textcolor(3+12*(func==1));
cputs(" Introducerea datelor arborelui ");
textbackground(BLACK);
textcolor(GREEN);
cputs("");
gotoxy(23,17);
cputs("----------------------------------------------------------------------------");
gotoxy(23,18);
cputs("");
textbackground(4*(func==2));
textcolor(3+12*(func==2));
cprintf(" Afisarea listei de incidenta
");
textbackground(BLACK);
textcolor(GREEN);
cputs("");
gotoxy(23,19);
cputs("----------------------------------------------------------------------------");
gotoxy(23,20);
cputs("");
textbackground(4*(func==3));
textcolor(3+12*(func==3));
cprintf(" Parcurgerea arborelui in largime ");
textbackground(BLACK);
textcolor(GREEN);
cputs("");
gotoxy(23,21);
cputs("--------------------------------------------------------------------------");
gotoxy(23,22);
cputs("");
textbackground(4*(func==4));
textcolor(3+12*(func==4));
cprintf(" Parcurgerea arborelui in adincime ");
textbackground(BLACK);
textcolor(GREEN);
cputs("");
gotoxy(23,23);
cputs("-----------------------------------------------------------------------");
gotoxy(23,24);
cputs("");
textbackground(4*(func==5));
textcolor(1+12*(func==5));
cprintf("
IESIRE!!!
");
textbackground(BLACK);
textcolor(GREEN);
cputs("");
gotoxy(23,25);
cputs("-----------------------------------------------------------------------");
switch(getch())
{
case 80:if(func<5)func++;else if (func==5) func=1; break;
case 72:if(func>1)func--;else if (func==1) func=5; break;
case 13:return func;
case 27:
clrscr();
ai();
exit(1);
}
}
}
void Parc_lat()
{
int v1,vc,b;
struct lista *ctl[15];
for (i=1;i<=n;i++)
ctl[i]=tl[i];
m1:clrscr();
printf("Introdu primul virf ");
scanf("%d",&v1);
if(v1<1 || v1>n)
{
puts("Virf inexistent!");
getch();
goto m1;
}
else s=ps(s,v1);
b=1;
while (b)
{
while (s || s2)
{
if (s)
{
pop_end(s,&vc);
if (!este(vc,j-1,tab) && vc!=0)
tab[j++]=vc;
if (ctl[vc]->inf!=0)
while (ctl[vc]->next)
{
if (!este(ctl[vc]->inf,j-1,tab))
s2=ps(s2,ctl[vc]->inf);
ctl[vc]=ctl[vc]->next;
}
}
else
{
stiva temp=s;
s=s2;
s2=temp;
}
}
b=0;s=NULL;
s2=NULL;
for (i=1;i<=n;i++)
if (!este(i,j-1,tab))
{
b=1;
s=ps(s,i);
break;
}
}
}
void pop_end(stiva &s, int *pai)
{
if (!s) return ;
if (s->next) pop_end(s->next,pai);
else
{
*pai=s->ai;
s=NULL;
}
}
void ai()
{
char s[]="
\0";
char c,p[60];
int i,j;
clrscr();
i=0;
while(s[i]!='\0')
{
j=0;
p[0]='\0';
while(j<=i)
{
p[j]=s[j];
j++;
}
p[j]='\0';
textcolor(14);
gotoxy(70-i,12);
cprintf("%s",p);
if(s[j]!='\0')
{
textcolor(0);
gotoxy(70-i,12);
cprintf("%s",p);
textcolor(3);
gotoxy(8,25);
}
i++;
}
}