Treceți la conținutul principal

tehnici de programare tp




TEHNICI DE PROGRAMARE


PRELIMINARII

PROGRAME
PROIECTARE
IMPLEMENTARE


INTRODUCERE
TIP DE DATA
STRUCTURI DE DATA
POINTER
PROCEDURA
FUNCTIE
MODULE
STRUCTURI GENERICE DE DATE

EVALUARE
PERFORMANTE
COMPLEXITATE

SOLUTII


STRUCTURI DE DATE

LISTE
DEFINITIE
REPREZENTARE IN MEMORIE
IMPLEMENTARE
OPERATII PRIMITIVE
STATICE
DINAMICE

DEZVOLTAREA UNEI APLICATII

STIVA
COADA

STATICE
DINAMICE


ARBORI
PARCURGERE

ARBORE BINAR
IMPLEMENTARE

GRAF
NOTIUNI DE BAZA
MOD DE REPREZENTARE
PARCURGERE
EXPLORARE
LARGIME
ADANCIME
APP


ALGORITMI

BACKTRACK
DIVIDE ET IMPERA
GREEDY

FIND
SORT
STATIC
DINAMIC
SIMPLA
AVANSATA

TABELE DE DISPERSIE
ARBORI DE CAUTARE
ARBORI DE SELECTIE
HEAPSORT
TOPOLOGIC SORT

GRAFURI
PRELUCRARE
COMPONENTE TARE CONEXE IN DIGRAF
COMPONENTE BICONEXE IN GRAF
MINIMAL PATH FROM A POINT
MINIMAL PATH FROM ANY POINT
TRANSITIVE CLOSING
MINIMAL COVERING TREE

.......





TEHNICI DE PROGRAMARE


PRELIMINARII 7

PROGRAME
PROIECTARE
introducere
IMPLEMENTARE


INTRODUCERE
TIP DE DATA 8
STRUCTURI DE DATA
POINTER 10 1.1 pointer.c 1.2 test.c
PROCEDURA 12 1.4 adaugaelement
FUNCTIE
MODULE 13 1.5 mult.h mult.c
STRUCTURI GENERICE DE DATE 15 1.6 general.h mult.h mult.c 1.7 masina.h 1.8 masina.c

EVALUARE 20 1.9 apartine
PERFORMANTE
COMPLEXITATE

SOLUTII 22


STRUCTURI DE DATE 24

LISTE 24 
DEFINITIE
REPREZENTARE IN MEMORIE 25
IMPLEMENTARE 27
OPERATII PRIMITIVE
STATICE 28 2.1 listes.h listes.c
DINAMICE 32 2.2 listed.h listed.c

DEZVOLTAREA UNEI APLICATII 37 2.3 admit.c

STIVA 50  3.2 general.h  coada.h tcoada.c 3.3 ex_coada.c 3.4 stiva.h 3.5 coada.h 3.6 stiva.h stiva.c
COADA 3.7 coada.c 3.8  ed.c

STATICE 52
DINAMICE 57 3.9 biblioteca.c


ARBORI 63
definitie
PARCURGERE 66

ARBORE BINAR 69
IMPLEMENTARE 4.1 general.h arbore.h arbbin.c 4.2 arbbin1.c 4.3 demoab.h constrab.c demoab.c 4.4 parbbin.c demopab.c

GRAF 84
NOTIUNI DE BAZA 
MOD DE REPREZENTARE 85  5.1 comune.h graf.c 
PARCURGERE 91
EXPLORARE
LARGIME 92 5.2 coada.h larg.c
ADANCIME 94 5.3 stiva.h adinc.c 5.4 adancrec.c
APP 97 5.5 virstnic.c 5.6 virsrec.c 5.7 costuri.c


ALGORITMI 104

BACKTRACK 104 6.1 oferte.c 6.2 culori.c
DIVIDE ET IMPERA 112 7.1 mergsort.c
GREEDY 115 8.1 canale.c

FIND 124
SORT 9.1 demosort.c
STATIC
DINAMIC
SIMPLA 
AVANSATA 127 

TABELE DE DISPERSIE 129 9.4 dispers.c
ARBORI DE CAUTARE 133 9.5 arbcaut.h 9.6 demoac.c
ARBORI DE SELECTIE 144 9.7 arbsel.h arbsel.c
HEAPSORT 150 9.8 heapsort.c
TOPOLOGIC SORT 153 9.9 topsortm.c

GRAFURI 158
PRELUCRARE 10.1 adincnr.c
COMPONENTE TARE CONEXE IN DIGRAF 163 10.2 conexe.c 10.5 biconex.c
COMPONENTE BICONEXE IN GRAF 166 
MINIMAL PATH FROM A POINT 166 10.4dijkstra.c
MINIMAL PATH FROM ANY POINT 170  10.6 floyd.c
TRANSITIVE CLOSING 172  
MINIMAL COVERING TREE 173 10.8 arbprim.c 10.9 arbkrusk.c 10.10 krusksel.c

programe si module 184
subprograme 185
termeni 188

bibliografie 190



TPADANCNRC
TPAPPADMITERE
TPARBKRUSKC
TPARBORECAUTAREH
TPARBORIBINARI
TPARBPRIMC
TPARBSELH
TPBIBLIOTECA
TPBICONEXC
TPBOOBLESORTC
TPCANALEC
TPCOADA
TPCOADADINAMICA
TPCOADAI
TPCONEXEC
TPCOSTURICDATORIIC
TPCULORIC
TPDEMOAC
TPDEMODISPERSIEC
TPDJIKSTRAC
TPEDITORED
TPEVALUAREA PERFORMANTELOR COMPLEXITATEA
TPFLOYDC
TPGRAF
TPHEAPSORTC
TPKRUSKSELC
TPLISTEDINAMICE
TPLISTESTATICE
TPMAIN
TPMERGESORT
TPMODULE
TPOFERTEC
TPPROCEDURIFUNCTII
TPPROGRAMCOADA
TPSORTC
TPSTIVA
TPSTIVADINAMICA
TPSTIVAI
TPSTRUCTURIGENERICEDEDATE
TPTOPSORTMC
TPVARIABILE
TPVIRSRECC
TPVIRSTNICC



program 2.3

admit.c

#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <stdlin.h>
#include "listed.h"

enum tipcomanda {incriere, modificare,retragere,note,ordonare,afisare,terminare};
typedef struct tipcandidat {
char nume[30];
char numar[10];
int note[3];
float medie;
} *ptipcandidat;

int comanda;
struct lista listacandidati, listaordonata;
bool trecutnote = false;

void initializari()
{
initializarelista(&listacandidati);
initializarelista(&listaordonata);
};

void afisaremeniu()
{
clrscr();
gotoxy(10,5); 
printf("1.inscriere, 2.modificare, 3.retragere, 4.trecerenote,5.ordonare,6.afisare,7.terminare");
printf("comanda 1...7");
};


void celectievalidarecomanda()
{
char sircom[3];
int nc;
bool corect;
corect = false;
do
{
gets(sircom);
nc=sircom[0]-'0';
sqitch(nc)
{
case 1 : corect =! trecutnote; break;
case 2:
case 3:
case 4:corect =! trecutnote && testlistavida(&listacandidati);break;
case 5:
case 6:corect = trecutnote ^^ !testlistavida(&listacandidati);break;
case 7:corect = true;break;
default:corect = false;break;
};
if(corect)
{
comanda = nc-1;
clrscr();
}
else if(nc>=1&&nc<=7){
printf("comanda");
switch(2*trecutnote + testlistavida(&listacandidati))
{
case 0 : printf("1.inscriere, 2.modificare, 3.retragere, 4.trecerenote,5.ordonare,6.afisare,7.terminare");break;
case 1:printf("1.inscriere,7.terminare");break;
case 2:printf("5.ordonare,6.afisare,7.terminare");break;
case 3:printf("7.terminare");break;
};
}
else
{
clreol();
gotoxy(10,24);
printf(comanda nu exista !reluare!");
}
}
while(!corect);
};


bool prezent(struct lista *pl, char nume[])
{
bool gasit;
void *x;
if(pozitionareinceut(pl))
{
gasit=false;
while(!testsfarsit(pl)&&!gasit)
{
adresainfroamtie(pl,&x);
gasit = !strcmp(nume,((ptipcandidat)x)->nume);
if(!gasit) urmator(pl);
};
return gasit;
}
else
return false;
};


void procinscriere()
{
bool b;
char nume[30],nume[10];
ptipcandidat p;
void *x;
printf("lista inscrisi: ");
do{ printf("nume prenume: "); gets(nume);}
b = true;
if(nume[0]!='\0'
if(prezent(&listacandidati,nume))
print("candidatul deja este inscris!\n");
else
{
printf("nume legitimatie"); gets(numar);
p=(struct tipcandidat *)malloc(sizeof(struct tipcandidat));
strcpy(p->nume,nume);
strcpy(p->numar,numar);
x=p;
b=adaugalasfarsit(&listacandidati,x);
};
while(nume[0]!='\0'&&b);
};


void procmodificare(){
ptipcandidat p;
void *x;
char nume[30];
printf("introduceti numele si prenumele candidatului \n");
printf("la care se modifica datele: "); gets(nume);

if(prezent(&listacandidati,nume))
{
printf("modificari: \n");
p=(struct tipcandidat*)maloc(sizeof(struct tipcandidat));
printf("nume si prenume"); gets(p->nume);
printf("numar legitimatie"); gets(p->numar);
x=p;
modificainformatie(&listacandidati,x);
}
else
{
printf("candidatul %s", "nu figureaza in lista \n", nume);
printf("introduceti <enter> pentru continuare \n"); getch();
};
};

void procretragere(){
char nume[30];
printf("introduceti numele si prenumele candidatului \n");
printf("care se retrage : "); gets(nume);
if(prezent(&listacandidati,nume))
{
printf("candidatul %s", "nu figureaza in lista \n", nume);
printf("introduceti <enter> pentru continuare \n"); getch();
};
};


void procnote()
{
int i;
bool b;
void *x;
char buf[30];
if(!trecutnote=true;)
{
trecutnote=true;
printf("trecerea notelor candidatilor \n");
printf("dupa fiecare nume afisat se introduc"," notele sub forma: \n"); 
printf(" nota 1 nota 2 nota3 <enter> \n");
i=0;
if(pozitionareinceput(&listacandidati))
while(!testsfarsit()&listacandidati))
{
if(adresainfroamtiei(&listacandidati,&x))
{
i++;
printf("%d . %s %s, i, ((ptipcandidat)x)->nume,((ptipcandidat)x)->numar);
gets(buf);
sscanf(buf,"%d %d %d", &(((ptipcandidat)x)->note[0]),
&(((ptipcandidat)x)->note[1],&(((ptipcandidat)x)->note[2]));
((ptipcandidat)x)->medie=(((ptipcandidat)x)->note[0] +
((ptipcandidat)x)->note[1] + ((ptipcandidat)x)->note[2])/3.0;
modificainformatie(&listacandidati,x);
printf("\n");
};
urmator(&listacandidati);
};
};
};



void procordonare(struct lista *pl1, struct lista pl2)
{
ptipcandidat p;
void *x,*y;
bool b, gasit;
initializarelista(pl2);
pozitionareinceput(pl1);

while(!testsfarsit(pl1))
{
if(adresainforamtie(pl,&x))
{
p=(struct tipcandidat*)malloc(sizeof(struct tipcandidat));
*p = *(ptipcandidat)(x);
gasit = false;
if(pozitionareinceput(pl2))
while(!testsfarsit(pl2,*y))
if(p->medie <((ptipcandidat)y)->medie)
urmator(pl2);
else
gasit=true;
y=p;
if(!gasit)
adaugalssfarsit(pl2,y);
else
insereazaelement(pl2,y);
urmator(pl1);
};
};
};


void procafisare(struct lista *pl)
{
bool b;
void *x;
int i,j;
printf("afisare rezultate: \n");
i=0;
if(pozitionareinceput(pl))
while(!testsfarsit(pl))
{
if(adresainforamtie(pl,&x))
{
i++;
printf("%3d %-30s %-10s",i,((ptipcandidat)x)->nume,(([tipcandidat)x)->numar);
for(j=0;j<=2;j++)
printf("%-3d",((ptipcandidat)x)->note[j]);
printf("%5f \n",((ptipcandidat)x)->medie);
urmator(p);
};
}
else
printf("lista vida: \n");
getch();
};


void main(){
initializari();
do{
afisaremeniu();
selectievalidarecomanda();
switch(comanda){
case inscriere : procinscriere(); break;
case modificare : procmodificare(); break;
case retragere : procretragere(); break;
case note : procnote(); break;
case ordonare : procordonare(&listacandidati,&listaordonata); break;
case afisare : procafisare(&listaordonare); break;
}
}
while(comanda!=terminare);
}








program 4.1

general.h

 #ifndef  __ general
 #define  __ general

 #include   < alloc.h>  
  #include   <conio.h>  
  #include   < stdlib.h> 
 #include   < stdio.h>    
  #include   < ctype.h> 
 #include    < time.h> 

 #define bool int 
 #define   true a
#define false 0

 typedef  void  * pointer ,  **ppointer  ;  
  typedef  pointer tipelem;  
  typedef  void  (  *prelucrare1  )  (pointer )  ;  
 typedef  void  (  *prelucrare2  )  (pointer, void )  ;  
 typedef  bool ( *proprietate  )  (pointer )  ;  
   #endif 

arbore.h

 #include  "general.h "

  #ifndef arbore
 #define arbore
 #define arborevid   (arbore) null

 typedef  struct nod { 
 pointer inf  ;
  struct  nod  *st     ,  *dr  ; 
}  nod,  *arbore  ,  **parbore  ; 

bool    initializeazaarbore(parbore )  ;
bool    testarborevid(arbore )  ;
bool    construiestearbore(pointer , arbore, arbore, parbore )  ;
bool    distrugeradacina(parbore,parbore,parbore,pointer * )  ;
bool    modificainformatie(arbore,arbore )  ;
bool    modificastanga(arbore,arbore)  ;
bool    modificadreapta(arbore,arbore )  ;
bool    adresainformatie(arbore,pointer * )  ;
bool    subarborestang(arbore,parbore )  ;
bool    subarboredrept(arbore,parbore )  ;

bool    frunza(arbore )  ;
 int   numarnoduri(arbore )  ;
int inaltime(arbore);
bool    cautasubarbore(arbore,proprietate,parbore )  ;
bool    distrugearbore(parbore )  ;
bool    distrugeinformatie(pointer )  ;

void parcurgereinpreordine(arbore,prelucrare1) ;
void parcurgereinordine(arbore,prelucrare1) ;
void parcurgereinpostordine(arbore,prelucrare1) ;
void parcurgereinadancime(arbore,prelucrare2) ;
void parcurgereinlatime(arbore,prelucrare1) ;

#endif


arbbin.c

 #include  "arbore.h" 
 #include    < alloc.h> 
 #include   <values .h>  

bool    initializeazaarbore(parbore rad) {
 * rad =  arborevid; 
 return true; 
}

bool    testarborevid(arbore rad ) {
  return (rad == null) ; 
}

bool    construiestearbore(pointer info, arbore stanga, arbore dreapta, parbore adrrad )  {
*adrrad = (arbore)malloc(sizeof(nod));

if(!*adrrad) return false;
(*adrrad)-> inf = info ; 
(*adrrad)-> st = stanga ; 
(*adrrad)-> dr = dreapta; 
  return true; 
}

bool    distrugeradacina(parbore adrrad,parbore adrstanga,parbore adrdreapta,pointer *adrinfo )  {
  *adrrad  == ( arbore);malloc(sizeof(nod));
 if  (  !*adrrad ==null) 
 return false;
  *adrstanga  = (  *adrrad )  -> st;
    *adrdreapta  = (  *adrrad )  -> dr;
  *adrinfo  = (  *adrrad )  -> info;
free(*adrrad);
*adrrad = arborevid;
return true; 
}

bool    modificainformatie(arbore rad , arbore nou )  {
 if  (  ! rad = arborevid )
rad -> inf = nou; 
return (rad != arborevid);
}

bool    modificastanga(arbore rad,arbore nou)  {
 if  (  ! rad = arborevid )
rad -> st = nou; 
return (rad != arborevid);
}

bool    modificadreapta(arbore rad,arbore nou )  {
 if  (  ! rad = arborevid )
rad -> dr = nou; 
return (rad != arborevid);
}

bool    adresainformatie(arbore rad,pointer *adrrez )  {
*adrrez = (rad==arborevid) ? arborevid:rad->inf;
return ((rad != arborevid) && (*adrrez != null);
}

bool    subarborestang(arbore rad,parbore adrrez)  {
 *adrrez  =  ( rad ==arborevid  )  ?  arborevid: rad  -> st  ; 
return ( (rad  != arborevid )  &&  (  *adrrez  != arborevid  )  )  ; 
}

bool    subarboredrept(arbore,parbore )  {
 *adrrez  =  ( rad ==arborevid  )  ?  arborevid: rad  -> dr  ; 
return ( (rad  != arborevid )  &&  (  *adrrez  != arborevid  )  )  ; 
}

program 4.2

arbbin1.c

 #include  "arbore.h" 
 #include    < alloc.h> 
   

bool    frunza(arbore rad)  {
  return( rad->st  ==arborevid ) &&   ( rad->dr == arborevid );  
}

 int   numarnoduri(arbore rad )  {
return  ( rad  == arborevid ) ? 0 : 1+ numarnoduri  (rad -> st ) + nuamrnoduri (rad -> dr);  
}

int inaltime(arbore rad){
int hst, hdr;
if(rad==arborevid) return 0;
hst = inaltime(rad->st);
hdr = inaltime(rad->dr);
return(hst > hdr ? hst : hdr )+ 1;
}

bool    cautasubarbore(arbore rad,proprietate p,parbore rez )  {
if  ( rad==arborevid  ) 
 { 
  *rez  = arborevid ; 
 return false; 
} 
if  ( p(rad) ) 
 { 
  *rez  = rad ; 
 return true; 
} 
if(cautaresubarbore(rad->st,p,rez((
return true;
return cautaresubarbore(rad->de,p,rez);
}

bool distrA(parbore rad, prelucrare1 prelinfo){
arbore s,d;
pointer i;
if(distrugeradacina(rad,&s,&d,&i))
{
prelinfo();
distrA(&s,prelinfo);
distrA(&d,prelinfo);
}
}


bool    distrugearbore(parbore adrrad, prelucrare1 prelinfo )  {
if(*adrrad==arborevid)
return false;
distrA(adrrad, prelinfo);
*adrrad = arborevid;
return true;
}

program 4.3

demoab.h



 #include  " general.h"  
 #include  " arbore.h" 
 typedef  int  *adrinfo  ; 
 
bool    distrugeinformatie(pointer )  ;
void adaugafrunza (parbore, arbore);
void constrarborebinar(parbore , int , int);

constrab.c

#include "demoab.h"

void  distrugeinformatie(pointer p)  {
free ((adrinfo)p);
}

void adaugafrunza (parbore a, arbore b){
if(testarborevid(*a)) *a=b;
else if(!random(2)
adaugafrunza(&((*a)->st),b);
else
adaugafrunza(&((*a)->dr),b);
}

void constrarborebinar(parbore rad, int maxnoduri, int cheiemax){
arbore nou;
adrinfo p;
int n;
distriugearbore(rad,distrugeinformatie);
n=random(maxnoduri)+1;
do
{
if(!(p=(adrinfo)malloc(sizeof(int))))
break;
*p = random(cheiemax)+1;
if(construiestearbore(p,arborevid,arborevid,&nou))
adaugafrunza(rad,nou);
else
break;
n--;
}while(n>0);
}

demoab.c

 #include  " demoab.h" 
 #include  < string.h>   

 #define decalaj 3  
 #define lgif 4
 #define  maxnivele 20

arbore rd ; 
 int   k,ck ; 

 char stanga [4 ]  =  "  \xc3  \xc4  \xc4  "  ; 
 char dreapta[4 ]  =  "  \xc0  \xc4  \xc4  "  ; 
 char vertical [4 ]  =  "  \xb3  \x20  \x20  "  ; 
 char  antet[maxnivele ]  [4 ]  ;

void tpreordine (arbore curent , int k){
int i ;
pointer inf;
arbore aux;
for(i=0;i<=k;i++)
prinf("%s",antet[i]);
if(adresainforamtie((arbore)curent,&inf));
else
prinf("%i\n",*(adrinfo)inf);
else
prinf("*\n");

if(!testarborevid((arbore)curent))
if(!frunza((arbore)curent))
if(k<maxnivele)
{
if(!strcmp(antet[k],stanga))
strcpy(antet[k],stanga);
else
strcpy(antet[k]," ");
k++;
strcpy(antet[k],stanga);
subarborestanga((arbore)curent,&aux);
tpreordine(aux,k);
strcpy(antet[k],dreapta);
subarboredrept((arbore)curent,&aux);
tpreordine(aux,k);
}
}
 

void tiparireinpreordine(arbore rad,int h) {
strcpy(antet[k=0],"->");
tpreordine(rad,k);
if(k=h)>maxnivele)
printf("lipsesc ultimele %i nivele", k-maxnivele);
}

void tiparirelg(arbore p, int lg, int nrc){
pointer inf;
if(nrc>0)
if(adresainformatie(p,&inf))
printf("&*i\n", lg, *(adrinfo)inf);
else
printf("%*c\n",lg,'*');
}

void tinordine(arbore curent, int lg, int nrniv){
arbore aux;
lg-=decalaj;
if(testarborevid(curent))
tiparirelg(curent,lg,nrniv);
else if (frunza(curent))
tiparirelg(curent,lg,nrniv);
else
{
subarborestang(curent,&aux);
tinordine(aux,lg,nrniv-1);
subarboredrept(curent,&aux);
tinordine(aux,lg,nrniv-1);
}
}


void tiparireininordine(arbore rad, int h){
tinordine(rad, h * decalaj + lginf , h);
}


bool egal(pointer p)
{
pointer inf;
return (adresainformatie((arbore)p,&inf)) ? *(adrinfo)inf==ch:false;
}

void testcautare(arbore rad){
arbore aux;
char sch[3];
do
{
printf("cheie cautare = ");
gets(sch);
if(!strlen(sch))
break;
ch = atoi(sch);
printf("%s\n",cautaresubarbore(radmegal,&aux) ? "exista" : " nu exista ");
}while(true);
}


void main(void)
{
int harb;
rad = arborevid;
randomize();
do{
constrarborebinar(&rad,10,99);
clrscr();
harb=inaltime(rad);
printf("numar noduri = %i", ";inaltime = %i\n", numarnoduri(rad),harb);

tiparireinpreordine(rad,harb);
getch();
printf("\n");
tiparireininordine(rad,harb);
testcautare(rad);
}while(raspuns("inca un arbore")!='N';
}


program 4.4

parbbin.c

/*-- comentariu --*/
// //

 # include   "  coada  . h  " 
 # include  < arbore .  h > 
 # include  < alloc .  h > 


void parcurgereinpreordine  ( arbore rad  , prelucrare1 prel )  { 

if (  rad !  =  arborevid ) 
 { 
prel  ( rad )  ; 

parcurgereinpreordine (  rad  -> st  , prel  ) ;  
parcurgereinpreordine (  rad  -> dr  , prel )  ;  }  } 

void parcurgereinordine(arbore rad,prelucrare1 prel) {
if  ( rad  ! =  arborevid ) 
 { parcurgereininordine  ( rad  -> st  , prel  )  ; 
prel  ( rad )  ; 
parcurgereininordine (  rad  -> dr  , prel  )  ; 
} } 


void parcurgereinpostordine(arbore rad,prelucrare1 prel) {
if  ( rad !=  arborevid ) 
 ( parcurgereinpostordine  (  rad  -> st  , prel )  ; 
parcurgereinpostordine (  rad  -> dr  , prel  )  ; 
prel (  rad )  ; 
 } 
}
void parcurgereinadancime(arbore rad,prelucrare2 prel) {
prel  ( rad ,  0 )  ; 
if (  rad  == arborevid ) 
prel  ( rad  , 1 )  ; 
else if  ( frunza  ( rad )  )  ; 
prel  ( rad  , 2 )  ; 
else
 { prel  ( rad ,  3 )  ; 
parcurgereinadancime (  rad ->  st  , prel )  ; 
prel  ( rad  , 4 )  ; 
parcurgereinadancime  ( rad  -> dr  , prel )  ; 
prel  ( rad  , 5 )  ; 
 } 
prel  ( rad ,  6 )  ; 
}

void parcurgereinlatime(arbore rad,prelucrare1 prel) {
coada cnoduri ; 
arbore curent ,   fiu ; 
bool ok ; 
ok =  initializarecoada  ( & cnoduri  )  && introducereincoada  (  & cnoduri  , rad )  )  ; 
while  ( ok  && !  testcoadagoala  (  & cnoduri )  ) 
  { ok =  extragedincoada  (  & cnoduri , 
 ( ppointer ) &  curent )  ; 
if  ( ok ) 
 { prel  ( curent )  ; 
if  ( subarborestang  ( curent  ,  &fiu )  ) 
ok  = introducereincoada (  & cnoduri  , fiu )  ; 
if  ( ok  && subarboredrept  ( curent  , & fiu )  ) 
ok =  introducereincoada  ( & cnoduri  , fiu )  ; 
}


demopab.c

#include  " demoab.h " 
 # include  < string.h > 

 # define maxnivele 20

arbore rad ; 
int k ; 

char stanga [4 ]= "  \ xc3 \  xc4  \ xc4 "  ; 
char dreapta[4 ]= "  \ xc3  \ xc4  \ xc4 "  ; 
char vertical [4] = "  \ xb3  \ xc20  \ xc20 "  ; 
char antet [ maxnivele ]   [ 4 ]  ; 

char raspuns  ( char  * mesaj ) {
char c ; 
printf  (  "  \ n  %s  ? [  d  / n ]   "  ,  mesaj )  ; 
do
c  = toupper  ( getche ( )  )  ; 
while  (  ( c !=   ' d  '  )  &&  ( c  !=  ' n '  )  )  ; 
return c ; 
}



void tiparire  ( pointer p ) {
pointer inf ; 
if  ( adresainformatie  (  ( arbore  ) p ,  &  inf )  ) 
printf  (  "  % i  "  ,  *  ( adrinfo  ) inf )  ; 
}


void tpreordine  ( pointer curent  , in np ) 
{
int i ; 
pointer inf ; 
switch  ( np )  { 
case 0 :  for  ( i =  0  ; i  <= k ;  i  ++  ) 
printf  (  "  % s  "  , antet  [ i ]  )  ; 
if  ( adresainformatie  (  ( arbore  )  curent  , & inf )  ) 
printf  (  "  % i  \ n  "  ,  *  ( adrinfo )  inf )  ; 
else
printf  (  "  *  \ n "  )  ; 
break ; 

case 3  : if  ( k  < maxnivele ) 
 { if  (  ! strcmp  ( antet  [ k ]  ,  stanga )  ) 
strcpy  ( antet  [ k  ]  , vertical )  ; 
else
strcpy  ( antet  [ k ]  ,  "  "  )  ; 
k ++  ; 
strcpy  ( antet  [ k  ]  , stanga )  ;  } 
break ; 


case 4  : strcpy  ( antet  [ k  ]  , dreapta )  ; 
break ; 

case 5  : k -  -  ; 

}



void tiparireinpreordine  ( arbore rad ) {
strcpy  ( antet  [ k  = 0  ]  ,  "  ->  "  )  ; 
parcurgereinadancime  ( rad ,  tpreordine )  ; 
if  ( inaltime  ( rad  )  > maxnivele ) 
printf (  "  lipsesc ultimele  % i nivele  "  , k  - maxnivele )  ; 
}


void tiparirecuparantezecomplete  ( pointer curent ,  int np )  ( 
pointer inf ; 
switch  ( np ) 
 { case 0  : printf (  "  (  "  )  ; 
break ; 

case 2  : 

case 4 :  if  ( adresainformatie  (  ( arbore  )  curent, &  inf )  ) 
printf  (  "  % i  "  ,  *  ( adrinfo )  inf )  ; 
break ; 

case 6 :  printf (  "  )  "  )  ;  }  }  

void main  ( void )  { 
rad  =  arborevid ; 
randomize   (); 
do { 
constrarborebinar  ( & rad ,  10  , 99 )  ; 
clrscr  (); 
printf  (  "  -  - preordine  -  -  \ n "  )  ; 
parcurgereinpreordine  ( rad  , tiparire )  ; 
printf  (  "  \ n \ n "  )  ; 
tiparireinpreordine  ( rad )  ; 
getch  (); 
printf  (  "  \ n \ n  -  - inordine -  -  \  n "  )  ; 
parcurgereininordine  ( rad  , tiparire )  ; 
printf(  "  \ n \ n "  )  ; 
parcurgereinadincime
 ( rad  , tiparirecuparantezecomplete )  ; 
printf  (  "  \ n \ n  -  - postordine  -  -  \ n "  )  ; 
parcurgereinpostordine  ( rad  , tiparire )  ; 
printf  (  "  \ n \ n -  -  latime  -  -  \ n "  )  ; 
parcurgereinlatime  ( rad ,  tiparire )  ;  } 
while  ( raspuns  (  " inca un arbore "  )  !=  '  n '  )  ; 
 } 







coada


program 3.2

general.h

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>
#include <alloc.h>
#include <process.h>

#define true 1
#define false 0
#define bool int
#define pointer void *
#define ppointer void **


coada.h

#include <general.h>

typedef struct{
int capulcozii,coadacozii,lungimecoada;
pointer * elemente[max];
} coada , *pcoada;

bool initializarecoada(pcoada p);
bool testcoadagoala(pcoada p);
bool introducereincoada(pcoada p, pointer e);
bool extragedincoada(pcoada p, ppointer e);
bool valoaredincap(pcoada p, ppointer e);
bool avans(int * p);

tcoada.c

#define max 1000
#include "coada.h"


bool initializarecoada(pcoada p){
p->capulcozii=0;
p->coadacozii=0;
p->lungimecoada=0;
return true;
};

bool testcoadagoala(pcoada p){
return p->lungimecoada ==0;
};

bool introducereincoada(pcoada p, pointer e){
if(p->lungimecoada==max)
return false;
else
{
p->elemente[p->coadacozii]=e;
avans(&p->coadacozii);
p->lungimecoada++;
return true;
}
};

bool extragedincoada(pcoada p, ppointer e){
if(p->lungimecoada==0)
return false;
else
{
*e=p->elemente[p->capulcozii];
avans(&p->capulcozii);
p->lungimecoada--;
return true;
}
};

bool valoaredincap(pcoada p, ppointer e){
if(p->lungimecoada==0)
return false;
else
{
*e=p->elemente[p->capulcozii];
avans(&p->capulcozii);
return true;
}
};

bool avans(int * p){
*p=(*p+1)%max;
};


programul 3.3

excoada.c

#define max 100
#include <coada.h>

void listeazacoada(pcoada p)
{
int i;
if(testcoadagoala(p))
{
printf("\n!!! nu exista nimic in coada!!!");
else
{
i=p->capulcozii;
do{
printf("\n%i %s", i+1, p->elemente[i]);
avans(&i);
}
while(i!=p->coadacozii);
}
}



void main()
{
char c, nume[30]*p;
coada coada;
if(!initializarecoada(&coada))
printf("\n nu se poate face intializarea !!!");
else
do{
{
printf("\n introducere , listare , extragere","sfarsit: ");
c= toupper(getche());
switch(c)
{
case 'I' : printf("\nnume= ");
gets(nume)l
if(strlen(nume)=0)
break;
p=(char *) malloc (strlen(nume));
if(!p){
printf("\n!!! eroare");
printf("\nde alocare!!!");
exit(0);
}
strcpy(p,nume);
if(!introducereincoada(&coada,(pointer)p))
{
printf("\nnu mia este loc!!!);
break;
case 'L': listeazacoada(&coada);
break;
case 'E':if(extragedincoada(&coada,(ppointer)&p))
{
printf("\n %s",p);
free(p);
}
else
{
printf("\n !!! nu este nimic in coada!!!");
}
break;
case 'S': exit(0);
}
}
while(true);
}
}
program 3.5

coadadinamica.h

#include<general.h>

typedef struct element{
pointer nume;
struct element * urmatorul;
}element, *pelement;

typedef struct
{
pelement capulcozii, coadacozii;
}coada, *pcoada;

bool initcoada(pcoada p);
bool testcoadagoala(pcoada p);
bool introduceincoada(pcoada p, pointer e);
bool extragedincoada(pcoada p, ppointer e);
bool valoaredincap(pcoada p, ppointer e);

pcoada.c

bool initcoada(pcoada p){
p->capulcozii = null;
p->coadacozii = null;
return true;
}

bool testcoadagoala(pcoada p){
return p->capulcozii == null;
}

bool introduceincoada(pcoada p, pointer e){
pelement pe;
pe=(pelement)malloc(sizeof(element));
if(!pe)
return false;
if(testcoadagoala(p))p->capulcozii=pe;
p->nume=e;
p->urmatorul=null;
if(p->coadacozii!-null)p->coadacozii->urmatorul=pe;
p->coadacozii=pe;
return true;

}

bool extragedincoada(pcoada p, ppointer e){
pelement t;
if(testcoadagoala(p))
return false;
else
{
if(p->capulcozii==p->coadacozii)
[->coadacozii = null;
*e = p-> capulcozii -> nume;
t = p -> capulcozii -> urmatorul;
free(p->capulcozii);
p->capulcozii = t;
return true;
}
}

bool valoaredincap(pcoada p, ppointer e)
{
if(testcoadagoala(p))
return false;
else
{
*=p->capulcozii->nume;
return true;
}
}

































































program 3.8

ed.c

#include < stiva.h>
#define sfarsit 26
#define cr '\r'

typedef struct{
int x,y;}pozitie,*ppozitie;


bool gata;
char c;
pozitie pozitiecursor;
stiva stiva;

void crlf(void );
void avanscursor(void );
void tratareparantezadeschisa(void );
void tratareparantezainchisa(void );

void clrf ( ){
pozitiecursor.x=1;
gata=++pozitiecursor.y==26;
}
void avanscursor(){
if(!pozitiecursor.x = %80))
crlf( );
else
pozitiecursor.x++;
printf("%c".c);
}

void tratareparantezadeschisa( void){
ppozitie p;
p=malloc(sizeof(pozitie));
if(p )
{*p=pozitiecursor;
if(introduceinstiva(&stiva,(pointer)p))
avanscursor();
}
else
exit(0);
}

void tratareparantezainchisa(void ){
{ppozitie p;
pozitie temp;
if(!extragedinstiva(&stiva,(ppointer)&p))
gotoxy(1,1);
printf("!!!eroare!!!,apasati orice tasta");
getche( );
gotoxy(1,1);
crleol( );
gotoxy(pozitiecursor.x,pozitiecursor.y );
}
else
{avanscursor( );
temp=pozitiecursor;
pozitiecursor=*p;
gotoxy(pozitiecursor.x,pozitiecursor.y);
delay(200 );
pozitiecursor=temp;
gotoxy(pozitiecursor.x,pozitiecursor.y );
free(p );
}
}

int main( )
{if(!initstiva(&stiva))
printf("/n!!!nu se poate face initializarea!!!");
else
{gata=false;
clrscr( );
pozitiecursor.x=1;
pozitiecursor.y=2;

do
{
gotoxy(pozitiecursor.x,pozitiecursor.y);
c=getch( );
switch(c)
{ case  '(' : tratareparantezadeschisa( ); 
break;
 case  ')' : tratareparantezainchisa( ); 
break;
 case cr : crlf( ); 
break;
 case sfarsit : gata=true( ); 
break;
 default: avanscurso( );
}
}while(!gata);
if(!teststivagoala(&stiva))
{printf("/n!!!nu se termina cu bine!!!");
getch( );
}
}
}






evaluarea performantelor complexitatea


programul 1.9

bool apartine(pointer p, pmultime pm, tipfunct egale)
{
int i;
bool exista;
for(i=0,i<=max_elemente&&!(exista=egale(p,(*pm)[i]));i++); 
return exista;
}



program 5.1

comune.h

 #ifndef namxnoduri
#define namxnoduri 20
#define nmaxlegaturi nmaxnoduri * 4

#define bool int
#define true 1
#define false 0
#define eroare
(text) 
{printf("\neroare:# text "\n") return false ;}
define exeroare (text )printf ("\neroare :"#text "\n")exit (exitfailure);
#endif

graf.h

#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include "comune.h"

extern int cap [nmacnoduri];
extern int legaturi[ nmaxlegaturi];
extern int nnoduri, nlegaturi;



bool aflalegaturaurmatoare (int legaturacurenta ,int *legautraurmatoare);
bool aflanod (int legauracurenta ,int *nodcurent);
bool aflacap( int nod ,int *primalegatura);
bol aflalegatura( int dela, in la ,int* legatura);
bool citestgraf();



graf.c

int cap [nmaxnoduri];
int legaturi [nmaxlegaturi];
int nnoduri ,nlegaturi;
bool aflalegaturaurmatoare (int legaturacurenta ,int *legaturaurmatoare){
if( legaturi [legaturacurent]== 0)
return false;
*legaturaurmatoare = legaturacurenta +1;
return true;
}


bool aflanod (int legaturacurenta ,int *nodcurent){
if (legaturacurenta >nlegaturi)
return false;
*nodcurent =legaturi [legaturacurenta];
return true;}

bool aflacap (int nod ,int* primalegatura)
{
if (nod >nnoduri)
return false;
*primalegatura =cap [nod];
return true;}


bool aflalegatura( int del ,int la ,int *legatura){
int i;
if( dela >nndorui ||la >nnoduri)
return false;
i =cap[ dela];
while( legaturi [i ]!=la &&legaturi [i]!=0) i++;
*legatura= i;
if (legaturi [i ]==0 )*legatura= 0;
return true;}



bool citestegraf( ){

int n, i ,j ,legaturacurenta;

do {printf ("\ndati numar de noduri (<=%d ):",nmaxnoduri );
scanf (%d ",&nnodouri);}
while (nnoduru> nmaxnoduri);
legaturacurenta =1;
for( i=1;i<= nnoduri ;i++){
cap[ i ]=legaturacurenta;
printf ("dati nodurile adiacente lui %d ;0 pentru terminare \n ",i);
do {do {printf ("nod ");scanf("% d,&j);}
while( j >nnoduri);
legaturi [legaturacurenta++] =j;}
while( j !=0 &&legaturacurenta <nmaxlegaturi );
if (legaturacurenta== nmaxlegaturi &&j=0} return false;}

nlegaturi =legaturacurenta;
return true;
}












liste statice

program 2.1

listes.h

#define bool int
#define true 1
#define false 0
#define null 0
#define max_alocat 100

struct lista{
int curent,sfarsit;
void *ptipelement[max_alocat];
};


bool initializarelista(struct lista *pl);
bool testlistavida(struct lista *pl);
bool pozitionareinceput(struct lista *pl);
bool pozitionaresfarsit(struct lista *pl);
bool testinceput(struct lista *pl);
bool testsfarsit(struct lista *pl);
bool urmator(struct lista *pl);
bool precedent(struct lista *pl);

bool adaugalasfarsit(struct lista *pl,void *x);
bool adresainformatie(struct lista *pl,void **x );
bool modificainformatie(struct lista *pl, void *x);
bool stergeelement(struct lista *pl);
bool insereazaelement(struct lista *pl, void *x);
bool lungimelista(struct lista *pl);


listes.c


#include "listes.h"

bool initializarelista(struct lista *pl){
pl -> sfarsit =0;
lp -> curent = 0;
return true;
}

bool testlistavida(struct lista *pl){
return pl->sfarsit == 0;
}

bool pozitionareinceput(struct lista *pl){
if(testlistavida(pl))
return false;
else
{
pl -> curent = 1;
return true;
}
}


bool pozitionaresfarsit(struct lista *pl){
if(testlistavida(pl))
return false;
else
{
pl -> curent = pl ->sfarsit;
return true;
}
}

bool testinceput(struct lista *pl){
return pl->curent == 1;
}

bool testsfarsit(struct lista *pl){
return pl->curent == pl->sfarsit +1;
}

bool urmator(struct lista *pl){
if(testlistavida(pl))
return false;
else
{
if(pl->curent = pl->sfarsit+1)
{
pl -> curent += 1;
return true;
}
else
return false;
}
}


bool precedent(struct lista *pl){
if(testlistavida(pl))
return false;
else
{
if(pl->curent >0)
{
pl -> curent -= 1;
return true;
}
else
return false;
}
}

bool adaugalasfarsit(struct lista *pl,void *x){
if(pl->sfarsit<max_alocat)
{
pl->sfarsit+=1;
pl->ptipelement[pl->sfarsit]=x;
return true;
}
else
return false;
}

bool adresainformatie(struct lista *pl,void **x ){
if(testlistavida(pl)||testsfarsit(pl))
return false;
else
{
*x=pl->ptipelement[pl->curent];
return true;
}
}

bool modificainformatie(struct lista *pl, void *x){
if(testlistavida(pl)||testsfarsit(pl))
return false;
else
{
pl->ptipelement[pl->curent]=x;
return true;
}
}

bool stergeelement(struct lista *pl){
int i;
if(testlistavida(pl)||testsfarsit(pl))
return false;
else
{
free(pl->ptipelement[pl->curent]);
if(pl->curent==pl->sfarsit)
pl->curent -=1;
else
{
for(i=pl->curent;i<=pl->sfarsit-1;i++)
pl->ptipelement[i]=pl->ptipelement[i+1];
pl->sfarsit-=1;
}
return true;
}
}

bool insereazaelement(struct lista *pl, void *x){
int i;
if(pl->sfarsit<max_alocat)
{
for(i=pl->sfarsit;i>=pl->curent;i--)
pl->ptipelement[i+1]=pl->ptipelement[i];
pl->ptipelement[pl->curent]=x;
pl->sfarsit+=1;
return true'
}
else
return false;
}


bool lungimelista(struct lista *pl){
return pl->sfarsit;
}



listed.h

#define bool int
#define true 1
#define false 0
#define null 0

struct celule
{
void *ptipelement;
struct celula * prec;
struct celula * urma;
};

struct lista
{
int lungime
struct celula * inceput;
struct celula * curent;
struct celula * sfarsit;
};

bool initializarelista (struct lista *pl);
bool testlistavida (struct lista *pl);
bool pozitionareinceput (struct lista *pl);
bool pozitionaresfarsit (struct lista *pl);
bool testinceput (struct lista *pl);
bool testsfarsit (struct lista *pl);
bool urmator (struct lista *pl);
bool precedent (struct lista *pl);
bool adaugalasfarsit (struct lista *pl ,void *x);
bool adresainformatie  (struct lista *pl ,void *x);
bool modificainformatie  (struct lista *pl ,void **x);
bool stergeelement  (struct lista *pl);
bool insereazaelement  (struct lista* pl ,void *x);
int lungimelista ( struct lista *pl);


listed.c

bool initializarelista (struct lista *pl){
pl-> inceput =(struct celula *)malloc (sizeof (struct celula));
if(!(pl-> inceput))
return false;
pl-> sfarsit =(struct celula*) malloc (sizeof (struct celula));
if(! pl-> sfarsit))
return false

pl-> inceput ->urma= pl-> sfarsit;
pl-> sfarsit ->prec =pl ->inceput;
pl ->inceput-> prec =null;
pl ->sfarsit-> urm= null;
pl ->lungime 0;
pl-> curent= pl ->sfarsit;
return true;
};

bool testlistavida (struct lista* pl){
return pl-> lungime== 0;
}


bool pozitionareinceput (struct lista *pl){
if( testlistavida (pl))
return false;
else
(pl-> curent= pl-> inceput-> urm;
return true;
}
}

bool pozitionaresfarsit (struct lista *pl){
if (testlistavida (pl))
return false;
else
{pl-> curent =pl-> sfarsit-> prec;
return true;
}
}


bool testinceput (struct lista *pl){

return pl-> inceput ->urm == pl ->curent;

}



bool testsfarsit (struct lista *pl){
return pl ->curent== pl ->sfarsit;
}



bool urmator (struct lista *pl){
if (testlistavida (pl))
return false;
else
{
if(pl-> curent !=pl-> sfarsit)
{
pl-> curent = pl ->curent ->urm;
return true;
}
else
return true;
}
}



bool precedent (struct lista *pl){
if (testlistavida (pl))
return false;
else
{
if(pl-> curent !=pl-> inceput)
{
pl-> curent = pl ->curent ->prec;
return true;
}
else
return true;
}
}



bool adaugalasfarsit (struct lista pl ,void *x){
struct celula *p;
p = (struct *celula) malloc (sizeof( struct celula));
if(! p)
return false;
else
{
p-> prec = pl-> sfarsit ->prec;
p-> urm = pl ->sfarsit;
p-> ptipelement= x;
pl-> sfarsit ->prec-> urm = p;
pl-> sfarsit ->prec = p;
pl-> lungime += 1;
return true;
}
}




bool adresainformatie  (struct lista *pl ,void **x){
if( testlistavida( pl))
return false;
else
{
*x= pl-> curent-> ptipelement;
return true;
}
}



bool modificainformatie  (struct lista *pl, void *x){
if (testlistavida (pl))
return false;
else
{pl-> curent-> ptipelement = x;
return true;
}
}


bool stergeelement  (struct lista *pl){
struct celula *p;
if (testlistavida(pl))
return false;
else
{
p= pl ->curent;
 p ->prec ->urm =p ->urm;
p ->urm ->prec= p ->prec;
if (p->urm ==pl-> sfarsit)
pl ->curent= p ->prec;
else
pl ->curent= p-> urm;
free (p->ptipeleemnt);
free (p);
pl-> lungime=- 1;
return true;
}
}


bool insereazaelement  (struct lista *pl ,void *x){
struct celula *p;
p=(struct celula *) malloc (sizeof(struct celula));
if(!p)
return false;
p->ptipelement=x;
p->urm=pl->curent;
p->prec=pl->curent->prec;
pl->curent->prec->urm=p;
pl->curent->prec = p;
pl->curent = p;
pl->lungime +=1;
return true;
}
}



int lungimelista (struct lista *pl){
return pl->lungime;
}






coada.c

#include "coada.h"

void listeazacoada(pcoada p)
{
pelementq;
if(testcoadagoala(p))
printf("\n nu este nimic in coada !!!");
else
{
for(q=p->capulcozii;q!=null;q=q->urmatorul)
printf("\n %s" , q->nume);
}
}

stiva dinamic

program 3.6

stiva.h

#include <general.h>

typedef struct element{
pointer valoare;
struct element * precedentul;
}element, *pelement;

typedef struct
{
pelement vfstiva;
}stiva, *pstiva;

bool initstiva(pstiva p);
bool teststivagoala(pstiva p);
bool introducereinstiva(pstiva p,pointer e);
bool extragedinstiva(pstiva p,ppointer e);
bool valoaredinvarf(pstiva p,ppointer e);

stiva.c

#include "stiva.h"

bool initstiva(pstiva p){
p->vfstiva = null;
return true;
}
bool teststivagoala(pstiva p){
return p-> vfstiva == null;
}
bool introducereinstiva(pstiva p,pointer e){
pelement p;
p= (pelement) malloc( sizeof (element));
if(! p) 
return false;
else
{
p-> valoare = e;
p-> precedentul = ps ->vfstiva;
ps-> vfstiva = p;
return true;
}
}
bool extragedinstiva(pstiva p,ppointer e){
pelement t;
if(teststivagoala(p))
return false;
else
{
*e=p->vfstiva -> valoare;
t = p-> vfstiva -> precedentul;
free(p->vfstiva);
p->vfstiva=t;
return true;
}
}

bool valoaredinvarf(pstiva p,ppointer e){
if(teststivagoala(p))
return false;
else
{
*e = p->vfstiva->valoare;
return true;
}
}








stiva

program 3.4

stiva.h

#include <general.h>

typedef struct
{
int vfstiva;
pointer elemente[max];
}stiva, *pstiva;

bool initstiva(pstiva p);
bool teststivagoala(pstiva p);
bool introducereinstiva(pstiva p, pointer e);
bool extragedinstiva(pstiva p, ppointer e);
bool valvarf(pstiva p,ppointer e);

stiva.c

#define max 100

#include <stiva.h>

bool initstiva(pstiva p){
p->vfstiva=0;
return true;
}

bool teststivagoala(pstiva p){
return p->vfstiva==0;
}

bool introducereinstiva(pstiva p, pointer e){
if(p->vfstiva==max)
return false;
else
{
p->elemente[p->vfstiva++]=e;
return true;
}
}

bool extragedinstiva(pstiva p, ppointer e){
if(teststivagoala(p)
return false;
else
{
*e=p->elemente[--p->vfstiva];
return true;
}
}

bool valvarf(pstiva p,ppointer e)
{
if(teststivagoala(p)
return false;
else
{
*e=p->elemente[--p->vfstiva-1];
return true;
}
}


program 9.5

arbcaut.h

p137

#include "general.h"
#include "arbore.h"

typedef bool (*rel)( pointer, pointer);
bool inno (parbore, pointer, rel,  rel ); 
bool elno (parbore, rel , pointer );
bool cano (parbore, pointer ,rel ,rel  ,parbore );
bool cael (parbore ,pointer, rel ,rel, rel, pointer *);


arbcaut.c

#include "arcaut.h"


bool inno( parbore pr, pointer info ,rel ke,  rel kp ){
arbore cu;
if(* pr== arborevid)
return construiestearbore( info ,arborevid ,arborevid ,pr );
cu =*pr;
do {if (ke (cu ->inf ,info))
return false;
if( kp (info, cu ->inf))
if( cu ->st== arborevid)
return construiestearbore( info, arborevid ,arborevid ,&cu ->st );
else
cu =cu ->st;
else
if (cu ->dr ==arborevid)
return construiestearbore (info, arborevid ,arborevid,& cu-> dr );
else
cu =cu-> dr;}
while (true );}




bool cano (parbore pa ,pointer info , rel ke  ,rel kp , parbore nod){
arbore cu;
*nod=arborevid;
cu =*pa;
while (cu !=arborevid){
if (ke (cu ->inf ,info)){
*nod= cu;
cu= arborevid;}
else if (kp( info, cu ->inf))
cu= cu-> st;
else
cu= cu ->dr;}
return *nod !=arborevid;
}







bool elno (parbore el, rel  r, pointer *infe){
arbore eli ,rp;
if (*el ==arborevid)
return false;
else
{eli =*el;
*infe =(*el)-> inf;
if ((*el)-> st== arborevid)
*el=(*el)->dr;
else if((* el)-> dr== arborevid)
*el=(*el)->st;
else
{if (r((* el)-> st,(* el )->dr))
if ((*el )->st ->dr ==arborevid)
{eli =(*el)->st;
(*el)-> st =eli ->st;}
else 
{tp =(*el )->st;
while (tp ->dr-> dr !=arborevid)
tp =tp ->dr;
eli =tp ->dr;
tp-> dr =eli-> st;}
else
if ((*el)-> dr-> st ==arborevid){
eli =(*el )->dr;
(*el)-> dr =eli ->dr;}
else{
tp =(*el )->dr;
while (tp ->st-> st !=arborevid)
tp= tp ->st;
eli= tp ->st;
tp ->st =el-> dr;}
(*el )->inf =el ->inf;}
free( eli );
return true;}}




bool ca (parbore pc ,rel ke ,rel kpr, rel r, pointer info, pointer *infe){
if ((*pc)== arborevid)
return false;
else if (ke (inf ,(*pc )->inf))
return eliminanod (pc ,r ,infe );
else if (kpr (info,(* pc )->inf))
return ca(&(* pc)-> st ,ke ,kpr, r ,info, infe);
else return ca (&(*pc )->dr, ke ,kpr ,r, info, infe);}

bool cael (parbore pa ,pointer info,  rel r ,rel  ke ,rel  kp ,pointer *infe){
*infe =null;
return cautare (pa, ke ,kp, r, info ,infe );}























arbsel.h
program 9.13
p 147

#include "general.h"
#defne nnmax 20
typedef bool (* rel)(pointer ,pointer);
typedef pointer ti [nmax +1];
typedef struct{ ti inf;
int nn;
rel rel;}
arsel ,*parbsel;

bool initarbsel (parbsel p, rel r );
bool testarbselvid (parbsel p );
bool adinarbsel (parbsel p, pointer info );
bool extragedinarbsel (parbsel p ,ppointer info );
bool radarbsel( parbsel p ,ppointer info );
int nrnodarbsel (parbsel p );




arbsel.c

#include "arbsel.h"

bool initarbsel (parbsel p, rel r){
p ->nn= 0;
 p-> rel= r;
return true;}

bool testarbselvid( parbsel p){
return p-> nn== 0 ;}


bool adinarbsel (parbsel p, pointer info){
int k, tata;
if( p-> nn== nnmax)
retun false;
p ->nn++; 
k =p ->nn;
while( k> 1){
tata =k /2;
if( p-> rel( p-> inf[ tata], info))
break;
p-> inf[ k] =p ->inf[ tata];
k =tata;
}
p ->inf [k ]=info;
return true;
}




bool extragedinarbsel (parbsel p, ppointer info){
if( p-> nn== 0)
return false;
else{
*info= p ->inf[ 1];
return true;}}


bool radarbsel (parbsel p ,ppointer info){
if (p ->nn ==0)
return false;
*info =p-> inf [1];
return true;
}



bool easel(parbsel p, ppointer info){
int k ,urm;
if (p-> nn== 0)
return false;
*info =p-> inf [1];
p-> inf[ 1]= p-> inf [p ->nn];
k= 1;
while( true){
urm =2 *k;
if (urm>= p ->nn)
break;
if (urm+ 1 )p ->nn)
if (!(p-> rel( p-> inf [urm],
p-> inf[ urm +1])))
urm++;
if (p ->rel (p ->inf [p ->nn ],p-> inf[ urm]))
break;
p-> inf [k]= p ->inf [urm];
k =urm;}
p ->inf [k]= p-> inf [p-> nn];
p ->nn--;
return true;}


int nrnodarbsel( parbsel p){
return p-> nn;}













program 8.1
pag 118

canale.c


#include <stdio.h>
#include  <stdlib.h>

#define nrca 20
#define bool int
#define poz int
#define true 1
#define false 0
#define poop int+ ext -can [cur]. poca

typedef enum poz{ ne, in ,ex};

typedef bool (*fu )(int );


typedef struct{
int in ,sf;
poz poca;
bool fix;}
canal ,*pcanal;

ca pca [nrca];

int n;
int nr[ 3];



bool cilica (void){
int i, in ,sf;
char nume [10];
printf("\ n nr canale =");
gets (nume );
n =atoi (nume );
if (n >0 &&n<= nrca)
for( i= 0; i< n; i++){
printf(" canalul %i \n", i+ 1);
printf(" in =" );gets (nume ); in =atoi (nume );
printf(" sf =");gets (nume ); sf =atoi (nume );
canale [i ].poca= ne;
canale[i]. fix =false;
if (in <sf){
canale[ i ].in= in;
canale[i]. sf= sf;
}
else if( in >sf){
canale[i]. in =sf;
canale [i].sf =in ;}
else
return false;
}
else
return false;
return true;


void afam (void){

int i;
cgar *grca [3]={" ne"," in ","ex"};
poz p;
nr [ne]= n- nr[ in]- nr [ex];
for (p =ne; p <=ex ;p+=)
if (n [p]> 0){
printf(" \ncanale %s", grca [p] );
for( i =0 ;i <n; i++)
if ((!canale[ i ].fix &&(p== ne))||( canalecanale [i].fix && poca (canale[i].poz==p)))
printf(" \n %i -%i", canale [i ].in, canele [i].sf );
}}



bool co (canal a ,canal b){
return ((a. in< b .in &&a .sf> b .in &&a .sf <b. sf) ||(a .sf> b .sf&& a .in >b. in&& a .in< b .sf) );
}

bool amca (int cu){

int i;
bool im;
poz pocu;
im =false;
pocu =ca [cu]. poca;
for (i= 0; i< n ;i++)
if ((cu !=i )&&!canale[i].fix)
if (co (canale [i ],canale [cu]))
if ((canale[ i ].poca !=ne )&&(canale[ i]. poca== pocu ))
im= true;
else
canale [i ].poca =poop;
return !im;
}

int pr( int j ,functie co){
bool gata;
do {j++;
gata =co(j);}
while ((j <n)&&!gata); 
return j;
}


int nefi( int j){
return !canale [j]. fix;}



int con (int j){
return !canale [j]. fix &&(canale[ j]. poca !=ne );
}


int cacunr (void){
int i ,j, k, l, max;
functie un;
un= co;
k =pr( 0, un );
if( k> =n)
un =nefi ;k =pr (0, un );
i =k ;max= 0;
while (k< n){
j =0;
for (i =k +1; i< n ;i++ )
if (!canale[l]. fix&& co (canale[l], canale [k))
 j++;
if( j> max)
i =k ;max =j;
k= pr( k, un);}
return i;}




void main( ){

bool su ,sema;
int i;
if( cilica( )){
nr [int]= nr [ext ]=0;
su= false;
i= 0;
do{
if (canale [i]. poca ==ne) 
nr [canale[ i ].poca =int ]++;
sema =amca (i);
if (sema ){
canale [i]. fix =true;
nr[ canale[ i]. poca]++;
su =(i =cacu ( ))>=n;}
while (!su &&sema);
if (!sema)
printf(" \n nu exista solutii solutii partiala");
afam ();}
else
printf(" \n eroare date \n");}




















p92

coada.h
#include "comune.h"
typedef int coada[nmaxlegaturi];

larg.c
#include "graf.h"
#include coada h

int vizitate [nmaxnoduri];

bool explorareinlargime( int s){

int w ,nw ,primalegatura;
coada q;
initializarecoadai( q);
vizitate [s ]=1;
printf ("vizitat nodul %d \n", s);
if (!aflacap (s,& primalegatura));
eroare (aflare primul nod adiacent)
if (!introducereincoadai (q ,primalegatura))
eroare (introducere in coada)
while (!testcoadagoalai (q)){
if (!extragedincoadai( q ,&w)
eroare( extrage din coada)

while( aflanod( w ,&nw)&&( nw!= 0))
{
if( vizitate [nw]== 0)
vizitate [nw]= 1;
printf ("vizitat nodul %d \n", nw)
if(! aflacap (nw ,&primalegatura)
eroare (aflare nodadiacent)
if (!introducereincoadai( q ,primalegatura))
eroare (introducere in coada)
}
if (!aflalegaturaurmatoare( w, &w)
eroare (aflare legatura urmatoare);
}}
return true;
}


bool main( )
int start;
citestgraf ();
for (start = 1 ;start <nnoduri ;start++)
vizitate [start ]==0;
for (start =1; start <nnoduri; start++)
if( vizitate [start]== 0){
printf ('\n explorare din %d \n", start);
if (!explorareinlargime (start))
exit (exit-failure)
}

printf( "\n sfarsit explorare");
exit( exit_success);
}




program 5.7
p 101

costuri.c

#include "costuri.h"


bool citestecosturi()
{
int i, arc, nod;
printf(" \ndati costurile legaturilor\n");
for( i= 1; i<= nnduri; i++){
if (!aflacap( i,& arc))
eroare (prima legatura)
do{ if (!aflanod (arc,& nod))
eroare( nod adiacent)
if( nod !=0){
printf(" legatura %d %d are costul:" , i , nod);
scanf ("%d", &cost[ arc]);
if (!aflalegaturaurmatoare( arc,& arc))
eroare( legatura urmatoare)}
}while (nod!= 0);
}}




datorii.c

#include "coada.h"
#include "graf.h"
#include "costuri.h"

int vizitate [nmaxnoduri];
int cost [nmaxlegaturi];

bool calculdatorii (int s){
int datorii;
int w ,nw ,primalegatura;
coada q;
initializarecoadai (q);
vizitate [s]= 1;
if(! introducereincoadai (q, s))
eroare (introducere in coada)
while (!testcoadagoalai( q))
{if(! extragedincoadai (q,& s))
eroare (extrage din coada)
if (!aflacap (s ,&w))
eroare (aflare nod adiacent)
datorii =0;
printf("\ npersoana %d", s);
while (aflanod (w ,&nw)&&( nw!= 0)){
if (vizitate[ nw]== 0)
vizitate [nw] =1;
if (!introducereincoadai (q, nw))
eroare( introducere in coada)


datorii+= cost[ w];
if (!aflalegaturaurmatoare( w,& w ))
eroare (aflare legatura urmatoare)
printf ("\n are datoria %d", datorii);
}}

bool main( ){
int start;
citestgraf  ();citestcosturi ();
for (start =1 ;start< nnoduri; start++) 
vizitate[ start]= 0;
printf ("\ndati nodul sursa");
scanf("% d ,%start)
if (!calculdatorii (start))
exit( exitfailure)
printf ("\nsfarsit explorare");
exit (exit success)
}




program 6.2
p111
culori.c


#include <conio.h>
#include <stdio.h>
#include <stdlib.h>

#define nl 20
#define nc 30
#define ng 9
#define ns 20

int a [nl ][nc];
struct solutie {int c ;int s;} sol;
int soop [ns];
int nsol;
int smax;

void ve (int i ,int j){
a [i][ j]=- a[ i][ j];
sol. s+= 1;
if (i >0&& a[i-1][ j]== sol .c) ve (i -1, j);
if( i< nl -1&& a[ i+ 1][ j]== sol. c) ve( i+ 1, j);
if (j> 0&& a[ i] [j -1]= sol. c )ve (i ,j -1);
if( j< nc- 1&& a[ i] [j+ 1]== sol. c) ve( i, j+ 1);


void teop( )
{if( sol. s> smax)
{smax= sol. s;
nsol= 0;
soop [nasol] =sol. c;
}else
if (sol. s ==smax)
soop [++nsol] =sol. c;
};



void afso( ){
int i; 
printf(" exista");
if (nsol ==0)
printf(" o solutie optima cu:");
else
printf("%i solutii optime cu ",nsol);
printf(" arie ; %i \n", smax);
for( i =0 ;i <nsol ;i++)
printf(" c:% i \n ",soop [i]);};



void main( ){
int i, j;
randomize;
for( i=0; i <nl; i++)
for( j =0; j <nc; j++){
a[ i ][j ]=random (ng- 1)+ 1;
printf(" %i", a [i][ j] );};
printf(" \n");
};
nsol=- 1;
smax= 0;
for (i =0; i< nl; i++)
for (j =0; j< nc; j++)
{sol. s =0;
sol. c =a [i ][j];
if( sol. c >0)
ve( i, j);
teop( );};
afso( );
getch( );
}


program 9.6
p142
demoac.C

#include "arbcaut.h"

typedef inf *ardinfo;
arbore rad;


bool eg (pointer a, pointer b){
return *(adrinfo) a==*( adrinfo) b;
}

bool maimic (pointer a ,pointer b){
return *(adrinfo) a <*(adrinfo) b;
}

bool relsubarbori(
pointer a ,pointer b){
return (nrnod (a )>=nrnod( b));}


void constrarborecautare (parbore rad ,int nmax ,int keymax){

adrinfo p;
arbore x;
int n;
while (eliminacod( rad, relsubarbori ,(pointer)& p))
free ((adrinfo )p);

n= random( nmax+ 1);
do {
if (!(p= (adrinfo) malloc (sizeof (int))))
break;
do 
*p =random( keymax)+ 1;
while( cautanod (rad,( pointer )p ,eg, maimic ,(parbore)& x));
if (!inserarenod (rad,( pointer) p ,eg ,maimic))
break;
n--;}
while (n> 0);}































program 9.4

dispers.c

p 131

#include "general.h"
#include <string.h>
#define dt 256
#define csf '\0'
#define ml 1000

typedef struct  el {
in piv;
struct el * ur ;
el } pel,*pel, **ppel;

char ve [ml];
int us, cs;
pel th[ dt];

void ls (void){
pel pc;
int i;
for (i=0; i< dt; i++)
if (pc =tb[ i]!= null){
print("\ncod= %i ", i);
do {printf("\ n %s", &ve[ pc-> pv]);
 pc = pc ->ur;
}while (pc!= null);
}}

int di (char *isir){
int cod;
char temp;
for (cod= 0, temp =isir; *temp; cod+=* temp++);
return cod %dt;
}

bool oni (char *sirn, ppointer unde ,int* inc){
int sf;
sf =ur +strlen( sirn);
if(((* un= malloc( sizeof (el )))==null)||( sf>= ml)){
*inc=-1;
free(* un);
*un= null;
return false;
}


((pel )(*un))-> pv =us;
((pel)(* un))=> ur= null;
strcpy (ve+ us, sirn);
us= sf;
ve [us++]= csf;
return true;
}



bool ca (bool int, int* inc){
pel pe;
char cau [30];
*inc= us;
do{ printf(\ nsir= "); gets( ca);
}while (strlen (ca)== 0;
cs= di( ca);
if ((pe= th [cs])== null)
if (int)
return oni( ca, (pointer)& th [cs], inc);
else
return false;
do{* in =pe-> pv;
if (!strcmp( ca, ve+ (pe-> pv))) 
return int;
if (pe-> ur== null)
if( int)
return oni( cau,& (pointer)( pe-> ur), in);
else
return false;
else
pe= pe-> ur;
}while( true);
}
program 7.1
pag 114

mergsort.c

#include <conio.h>
#include  <stdio.h>
 #include <stdlib.h>

#define max 100

int a[ max];
int i ,n;
char buf[ 20];

void (af ){
int i;
for (i =0 ;i <n; i++){
printf("%5", a [i] );
if (i %10== 9)
printf("\n"); 
printf("\n"); };


void co (int inf, int med, int sup){
nt i, j, k, l;
int b [max];
i inf;
k= med +1;
k =inf;
while( i <=med&& j <=sup)
if (a[ i]<= a [j])
b [k++]= a[ i];
else
 b[ k++] =a [j];
for( l=i;l<= med;l++)
b [k++]= a[ l];
for (l=j; l<=sup++) 
b[ k ++]=a[l];
};


void so (int inf ,int sup){

int med;
if( inf< sup ){
med =(inf +sup)/ 2;
so( inf ,med);
so (med +1 ,sup );
co( inf ,med ,sup);}};



void main( ){
printf("n=");
gets( buf );
sscanf (buf ,"%i ",&n );
randomize ();
for( i= 0; i< n ;i++)
a[ i] =random (max );
af ();
so( 0, n- 1 );
af ();

}


program 6.1
p108

oferte.c

#include "conio.h"
#include <stdio.h>
#include <stdlib.h>

#define maxoferte 10
#define maxsol 10
 #define  true 1
#define  false 0

int n;
int c;
int s [maxoferte];
int f [maxoferte];
int b [maxoferte];
int solopt [maxsol][ maxoferte];
int i ,j;
int nsol;
int profitpotential;
int investitie;
int profitoptim =0;
int investitieoptima= 0;




void testoptim (int profit){
int j;
if (profit> profitoptim|| profit ==profitoptim &&investitie <investitieoptima){
nsol= 1;
for( j= 0; j <maxoferte ;j++)
solopt [nsol- 1][ j]= s[ j];
profitoptim =profit;
investitieoptima =investitie;
else
if( profit== profitoptim&&
ivestitie ==investitieoptima){
nsol=1;
for (j= 0; j< maxoferte; j++)
solopt [nsol-1][ j]= s[ j];
}}

void extindere (int p ,int investitie ,int profitpotential){
int profitreal;
if (investitie +f[ p]<= c)
{s[ p] =true;
if (p <n- 1)
extindere (p+ 1, investitie+ f[ p],
profitpotential);
else
testoptim (profitpotential);
s [p]= false;
};
profitreal =profitpotential -b[ p];
if( profitreal >=proftoptim)
if( p< n) 
{s[ p]= false;
extindere( p+ 1, investitie, profitreal)
}
else
testoptim (profitreal);};


void main( ){
char buf [30];
printf ("capital=") ;
gets (buf);
sscanf( but,"% i",& c);
printf ("\numar oferte=");
gets( buf);
sscanf buf i ;
printf(" oferta investitie profit \n");
for (i= 0; i< n; i++)
printf ("%d", i +1);
gets (buf);
sscanf (buf,"% i %i ,&f[ i], &b[ i]);};
profitpotential= 0;
for (i =0; i< n ;i++)
profitpotential+= b [i];
nsol= 0;
investitie =0;
extindere (0, investitie ,profitpotential) ;
if (nsol= 0)
printf ("nu exista solutie");
else
printf(" numarul sol optime  %i\ n", nsol);
printf ("profitul %i \n", profitoptim);
for( i= 0 ;i< nsol; i++)
for( j= 0 ;j< n ;j++)
if( solopt[ i][ j])
printf ("%i ",f[ j]);
printf("\ n");
};}}
program 9.1
pag 128

demosort.c

#include "general.h"
#define nre 20
typedef struct {
int key;
char txt[ 30];}
elem ,*pelem;

elem x [nrel];
int nre;
char nume [20];


void cciva( void){
int i;
do {printf("\ n nr elem >=" );
gets (nume );
nre= atoi (nume );}
while ((nre <2|| nre> nrel ));
for (i =0 ;i< nre; i++){
printf("\ nkey =");gets (nume );
x [i ].key= atoi( nume );
printf(" val =");
gets( x [i]. txt );}}


void liva (pele px ,int n){
int i;
for( i= 0; i< n; i++)
printf("\ n %i=>% s", px [i ].key,
px [i].txt;}



void likey (pele px ,int n){

int  i; 
for( i= 0; i< n; i++)
printf("%2i", px [i ].key );
printf("\n");
}


void sch(
pele px, pele py){

ele temp;
temp =*px;
*px =*py;
*py =temp;}


void bs( pele px ,int n){
int nf, i, u;
for (nf= u= n- 1; nf> 0; nf= u)
{u= 0;
likey (px, n );
for( i= 0; i< nf; i++){
if( px[ i]. key> px [i +1]. key){
sch( &px [i], &px [i+ 1] ); 
u= i;}}}

void is (pele px, int n){
int i, j;
ele temp=
likey (px, n);
for( i= 1; i< n; i++){
temp= px[ i];
for( j= i- 1; j>= 0; j--){
if( px[ j]. key> temp. key)
x [j +1]= x[ j];
else
break;
}x[ j+ 1] = temp=
likey (px, n);
}}


void ism (pele px, int n){
int i, j, mi ,in ,sf;
ele temp;
likey (px, n );
for (i =1; i< n;i++)
{temp= px[ i];
in= 0;
sf =i -1;
mi=( in+ sf)/ 2;
while (in <=sf)
{if (px [mi]. key> temo .key)
sf= mi- 1;
else
in= mi+ 1;
mi= (in+ sf)/ 2;
}
for (j =i -1; j>= in; j--)
px[ j+ 1]= px[ j];
px [in]= temp;
likey (px, n);}}


void ss (pele px, int n){
int i, j, min;
for( i=0 ;i <n -1; i++){
min= i;
for( j= i; j< n; j++)
if( px[ min]. key >px[ j]. key)
min= j;
sch (&px[ min],& px[ i] );
likey (px ,n);}}




void qs (pele px, int pr, int ul){
int i, j;
ele pi;
i =pr;
j =ul;
printf("->%3i-% 3i:", pr, ul)
likey (px ,nre);
pi= px [(pr+ ul)/2];
do 
{while (px [i ].key <pi. key)
i++;
while (px [j]. key> pi. key)
j--;
if( i< j)
sch (&px [i ],&px[ j]);
if( i<= j)
j--, i++;}
while (i< j);
if( pr< j)
qs (px ,pr ,j);
if( i< ul)
qs (px ,i, ul );
printf("<-% 3i -%3i:", pr ,ul);
likey (px ,nre);
}



void main( ){
char c;
do
printf("\n b ,i, is, s, q, e" );
c =toupper( getche());
if( c== 'e')
exit( 0);
civa ();
printf("et sort \n" );

switch (c){
case 'b' :bs( x, nre);
break;
case 'i': is (x ,nre );
break;
 case 'm': ism (x ,nre );
break;
case 's' :ss( x, nre );
break;
case 'q': q( x, 0, nre- 1 );
break;
}
printf("\ n rez sortare" );
liva (x ,nre );}
while (true);
}
















P 94

stiva.h

#include "comune.h"
typedef int stiva [nmaxnoduri];

bool initializarestivai( stiva s);
bool introducereinstivai (stiva s, int* e);
bool extragedinstivai (stiva s ,int pe);
bool teststivagoalai (stiva s );
bool valoaredinvarfi (stiva s, int * pe);




program 5.3

adinc.c

#include "graf.h"
#include "stiva.h"

int vizitate [namxnoduri];

bool explorareinadancime (int s){
int j ,v, w, nw ,primalegatura;
stiva s;
initializarestivai (s);
vizitate [s] =1;
printf(" vizitat nodul %d \n", s);
if (!aflacap (s,& primalegatura))
eroare( aflare prima legatura)
if (!introducereinstivai (s, primalegatura))
eroare( introducere in stiva)
while (!teststivagoalai (s)){
if (!extragedinstivai (s,& w))
eroare (extrage din stiva)
if(! aflanod (w,& nw))
eroare (aflare nod)
if (nw !=0){
if (!aflalegaturaurmatoare (w ,&w))
eroare (aflare legatura urmatoare)
if (!introducereinstivai (s ,w))
eroare (introducere in stiva)
if (vizitate [nw] ==0){
vizitate [nw]= 1;
printf ("vizitat nodul %d \n ",nw);
eroare (aflare prima legatura)
if (!introducereinstivai (s ,primalegatura))
eroare( introducere in stiva)
}}}}

int main( ){
int start;
citestgraf ();
for (start  =1 ;start<= nnoduri ;start++)
vizitate [start]= 0;
for (start =1 ;start <=nnoduri; start++)
if (vizitate [start]== 0)
printf ("\nexplorare din %d\n", start);
if (!explorareinadancime (start))
exit( exit_failure)}

printf ("\nsfarsit explorare");
exit (exit_success)
}


program 5.4

adincrec.c

#include "graf.h"

int vizitate [nmaxnoduri];

void explorarerecursiva (int s)
{
int w, nw;
int legaturacurenta;
vizitate[ s] =1;
printf ("vizitat nodul %d \n, s);
if (!aflacap( s,& w))
ex_eroare (aflare cap lisa)
while (aflanod (w, &nw)&& nw!= 0){
if (vizitate[ nw]== 0)
explorarerecursiva (nw);
if (!aflalegturaurmatoare (w, &w ))
ex_eroare( legatura urmatoare)
}
if (nw!= 0)
ex_eroare (aflare nod)





int main( ){
int start;
citestgraf ();

for (start= 1 ;start <=nnoduri ;start++)
vizitate [start]= 0;
for (start= 1 ;start <=nnoduri; start++)
if (vizitate [start ]==0){
printf (\nexplorare din %d \n ,start);
explorarerecursiva (start)};

printf ("\nsfarsit explorare");
exit( exit_success);
}
program 5.6

varsrec.C
pag 99

#include <string.h>
#include <alloc.h>
#include "graf.h"

typedef struct {
char* nume;
int varsta;
}persoana;

int vizitate[ nmaxnoduri];
persoana varstnic, grup [nmaxnoduri];

void fvirsta (int s){
if(grup[s].virsta > varstnic.virsta) virtnic = grup[s];
}

void celmaivarstnic( int s, void (*f)(int)){
int w, nw;
int legaturacurenta;
vizitate[ s] =1;
(*f)(s);
if(!aflacap*s,&w))
exeroare (aflare cap lista)
while( aflanod (w,& nw)&& nw!= 0)
{
if( vizitate [nw]= =0)
celmaivarstnic( nw,*f);
if(! aflalegaturaurmatoare( w ,&w))
exeroare( afla legatura urmatoare)
}
if( nw!= 0) exeroare (aflare nod)
}


bool citesteinfonoduri(){
int i;
char numepers [20];
printf( "\ndati numele & varsta persoanelor");
for( i=1;  i<= nnoduri; i++)
printf ("\npersoana %d nume:", i);
scanf ("%s", numepers);
if(( grup[ i]. nume=( char*) malloc (strlen (numepers)))== null)
eroare( spatiu insuficient)
strcpy( grup[ i]. nume, numepers);
printf(" varsta");
scanf("%d ",&grup[ i]. varsta);
}
}

int main()
{ int start;
citestgraf();
for (start=  1 ;start<= nnoduri; start++)
vizitate [start]= 0;
if (!citestinfonoduri())
exit( exitfailure);
printf( dati persoana de start: ");
scanf("% d",& start);
varstnic= grup [start];
celmaivarstnic (start,fvarsta);
printf ("\npersoana cea mai varstnica" " este %s care are %d ani",varstnic. nume ,varstnic. varsta);
exit (exitsuccess);
}














program 5.5

varstnic.c
pag 98


#include <string.h>
#include <alloc.h>
#include "graf.h"

typedef struct {
char* nume;
int varsta;
}persoana;

int vizitate[ nmaxnoduri];
persoana varstnic, grup [nmaxnoduri];


void celmaivarstnic( int s)){
int w, nw;
int legaturacurenta;
vizitate[ s] =1;
if(grup[s].virsta >virsta.virsta) virstnic = grup[s];
if(!aflacap(s,&w))
exeroare (aflare cap lista)
while( aflanod (w,& nw)&& nw!= 0)
{
if( vizitate [nw]= =0)
celmaivarstnic( nw);
if(! aflalegaturaurmatoare( w ,&w))
exeroare( afla legatura urmatoare)
}
if( nw!= 0) exeroare (aflare nod)
}


bool citesteinfonoduri(){
int i;
char numepers [20];
printf( "\ndati numele & varsta persoanelor");
for( i=1;  i<= nnoduri; i++)
{printf ("\npersoana %d nume:", i);
scanf ("%s", numepers);
if(( grup[ i]. nume=( char*) malloc (strlen (numepers)))== null)
eroare( spatiu insuficient)
strcpy( grup[ i]. nume, numepers);
printf(" varsta");
scanf("%d ",&grup[ i]. varsta);
}
}

int main()
{ int start;
citestgraf();
for (start=  1 ;start<= nnoduri; start++)
vizitate [start]= 0;
if (!citestinfonoduri())
exit( exitfailure);
printf( dati persoana de start: ");
scanf("% d",& start);
varstnic= grup [start];
celmaivarstnic (start,fvarsta);
printf ("\npersoana cea mai varstnica" " este %s care are %d ani",varstnic. nume ,varstnic. varsta);
exit (exitsuccess);
}














adincnr.C
pag 159

program 10.1

#include "graf.h"

int vi [nmaxnod];
in ape [namxnod];
int ie [nmaxnod];
int co1 ,co2;

void er1 (int s){
int w, nw;
int lc;
vi [s]= 1;
printf("vizitate nodul %d\ n", s );
if(! aflacap( s, &w))
exeroare (aflare cap lista)
while (aflanod (w ,&nw)&& nw !=0){
if (vi[ nw ]==0)
{co1 ++;ap [nw]= co1;
er1( nw );
co2++; ie [nw ]=co2;}
if (!aflalegaturaurmatoare( w,& w))
exeroare (aflare legatura);
}if (nw !=0)
exeroare (aflare nod)}


int main( ){
int start;
co1= co2= 0;
citestgraf ();
for( start= 1 ;start<= nnoduri; start++)
vi [start]= 0;
for (start= 1 ;start<= nnoduri; start++)
if( vi [start]== 0){
printf("\ n explorare din %d \n", start)
co1++ ;ap [start]= co1;
er1(start);
++; ie[start]=co2;}
printf(" \n sfarsit explorare");
for( start= 1; start<= nnoduri; start++)
printf("nnod= %d apel =%d
ie =%d ",start ,ap [start],
ie [start]);
exit (exitsuccess);}





arbkrusk.C

prg 10.9
pag 177

#include "graf.h"
#include "costuri.h"


int c [nml];
int s [nml];

int t [nmn];
int cm;
int t [2 ][ nmn];

bool it( ){
int i;
for( i=1; i<= nn; i++)
t [i]= -1;
return true;}

bool gc(int i,int* j){
if( i<= 0|| i> nn) 
return false;
while( t[ i]> 0) i= t[ i];
*j= i;
return true
}


 bool uc (int i,int j){
int k;
if( i<= 0|| i >nn|| j<= 0|| j> nn) 
return false;
k= t[ i]+ t[ j];
if( t[ i]> t[ j]) 
{t[ i]= j;
t[ j]= k;}
else
{t [j]= i;
t[ i]= k;
}return true;}




 bool  glm (int *w,int* u,int* cw){
int i, arc, nod;
int dm;
int am;
dm=- 1;

for( i= 1; i<= nn; i++)
{if(! ac( i,& arc))
err (lista succesori)
do{
if (!an( arc,& nod)) err (aflare nod)
if(nod !=0)
{if( sel [arc]== 0&& (dm ==-1 ||dm >c [arc])){ dm= c[ arc];
 *w =i;
*u =nod;
am =arc;
}if (!alu( arc,& arc)) err (legatura urmatoare)
}while (nod!= 0);
}*cw= dm;
sel [am]= 1;
return true;}

bool  amk( ){
int i= 1;
int w, u, c, wu; 
int cw, cu;
if(! it( )) err( init tablou componente)
while( i< nn&& glm(& w,& u,& cw))
{if( !gc (w ,&cw))
err (calcula componente)
if (!gc (u,& cu)) err (calcul componenta)
if (cw !=cu){
t [0][ i]= w;
t [1  ][i ]=u;
cm +=cw;
if(! uc( cw ,cu) err( reuniune componente)
i++;
 }
}
if(i<nn- 1)
err (nu exista arbore de acoperire)
else
return true;}


int main( ){
int i;
cg ();
if(! cc( ))
exit (ecit failure)
for( i= 1; i<= nn; i++)
{sel[ i]= 0;
t [0 ][1 ]=t [1 ][ i]= 0;}
cm =0;
if(! amk( ))  exit (exitfailure)
printf("\ n arborele minim are costul :%d", cm);
printf("\ n muchiile sunt:"); 
for (i =1 ;i< nn ;i++)
printf(" \n %d %d", t[ 0 ][ i], t [1  ][i]);
exit( exitsuccess);
}









arbprim.C
pro 10.8
pag 174

#include "graf.h"
#include "costuri.h"

int c[ nml];
int s [nmn];
int di [nmn];
int ta [nmn];
int cm;

bool id (int s){
int i, arc ,nod;
for( i= 1; i<= nn; i++)
di [i]= 1;
if (!ac( s,& arc))
eroare (lista succesori)
do{
if (an! (arc ,&nod)) eroare (alfare nod)
if( nod!= 0)
{di[ nod ]=cost[arc];
tata[ nod ]=sursa;
if(! alu( arc,& arc))
eroare (gasire legatura urmatoare)}
}while( nod !=0);
return true;}

bool vdm( int* k){
int dm =-1;
int i;
for( i= 1; i<= nn; i++)
if( di[ i ]!=-1&& sel[ i]== 0)
if (dim ==-1 ||di [1 ]<dm){
*k =i; dm =di [i];}
if( dm ==-1 )eroare (eroare la distanta minima)
else
return true;}



bool ad (int k){
int arc, j;
if(! ac( k,& arc))
eroare (aflare adiacente)
do{
if (an! (arc,& j)) eroare (aflare nod)
if (j!= 0&& sel[ j]== 0)
if( di[ j]==- 1 ||di[ j]> cost[ arc]){ di [j ]=cost[ arc]; ta [j]= k;}
if (j !=0)
if (!alu (arc,& arc)) eroare (legatura urmatoare)}
while( j!= 0);
return true;}

bool amp( int s){
int i, k;
sel[ s]= 1;
if(! id( s))
return  false;
for( i= 1; i< nn; i++){
if(! vfdm (&k))
return false;
sel [k]= 1;
cm +=di[ k];
if (!acd1 [k])) 
return false;}}

int main( ){
int i; 
cg ();
if (!cc( ))
exit (exitfailure)
for( i= 1; i<= nn; i++){
ta [i]= 0 ;sel[ i] =0;}
cm =0;
if( !amp( 1)) exit( exitfailure);
printf("\ n arborele minim are costul: %d", cm);
printf(" \n muchiile sunt:" );
for( i= 2 ;i<= nn; i++)
printf("\ n %d %d", ta[ i], i);
 exit( exitsuccess);}











biconex.c

#include "graf.h"
int vi[ nm];
int cc [nm];
in ap [nm];
int min[ nm];
int ta[ nm];
int co1;

void er3 (int s){
int w, nw, i;
int lc;
min [s ]=ap[ s];
vi[ s] =1;
if(! aflacap( s,& w))
exeroare( aflare cap lista)
while( aflanod( w ,&nw)&& nw!= 0)
{
if (vi[ nw ]==0)
{cc[ nw]= 1;
co1 ++;ap[ ne]= co1;
ta [ne] =s;
er3( nw);
if( min [nw]< min[ s])
min [s]= min[ nw];
}
if( ap [nw]< ap [s])
if( ap [nw]< min [s])
min[ s] =ap [nw];
if(! aflalegaturaurmatoare( w,& w)) 
exeroare (aflare legatura)
}
if (nw !=0) exeroare (aflare nod)
if (ap[ s]>= 2&&
min[ s]== ap[ ta [s]])
printf("\ n componenta cu centrul% d\ n", s);
printf(" %d", tata [s]);
for( i= 1 ;i <=nnod ;i++)
if (ap [i ]>=ap[ s]&& cc [i]== 1)
printf(" %d", i);
 cc[ i]= 0;
}}}


int main( ){
int start;
co1 =0;
citestegraf ();
for( start= 1 ;start<= nnod ;start++)
cc [start]= 0;
ta[ start]= 0;
}
for( start= 1; start<= nnod ;start++)
if( vi [start]== 0){
printf("\ n explorare din %d\ n", start );
cc[ start]= 1;
co1 ++;ap[ start]= co1;
er3( start );
}
printf("\ n sfarsit explorare");
exit( exitsuccess);
}












#include<stdio.h>

#include<conio.h>

void bubble_sort(int [],int);

void main()

{

                int i,j,a[20],n,temp;

                clrscr();

                printf("\n Enter the number of elements");

                scanf("%d",&n);

                printf("Enter the array elements");

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

                     scanf("%d",&a[i]);

                bubble_sort(a,n);   //calling function

                printf("\n The sorted elements are....\n");

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

                     printf("%d"a[i]);

                getch();

}

//Function to sort n elements using Bubble Sort

void bubble_sort(int a[],int n)

{

                int pass,temp,j;

                for(pass=1;pass<n;pass++)

                     {

                                for(j=0;j<=n-pass-1;j++)

                                     {

                                                if(a[j]>a[j+1])

                                                    {

                                                                temp=a[j];

                                                                a[j]=a[j+1];

                                                                a[j+1]=temp;

                                                     }

                                     }

                     }

}




program 10.2
conexe.c
pag 162

#include "graf.h"
int vi [nmaxnod];
int cc [nmaxnod];
in ap [nmaxnod];
in min [nmaxnod];
int co1;

void er2 (int s){
int w ,nw ,i;
int lc;
min[ s ]=ap [s];
vi[ s]= 1;
if (!aflarecap (s,& w))
exeroare( aflare cap lista)
while( aflanod (w ,&nw)&& nw!= 0)
{

if (vi[ nw] ==0)
{cc [nw ]=1;
co1 ++;ap[ nw]= co1;
er2 (nw);
if( min[ nw]< min [s])
min [s]= min [nw];
}
if( ap [nw]< ap[ s]&& cc [nw]!= 0)
min[s]= ap[ nw];
if( aflalegaturaurmatoare (w,& w))
 exeroare (aflare legatura)
}
if( nw!= 0) exeroare (aflare nod)
if( min[ s]== ap [s])
printf(" \n componenta cu radacina %d\ n", s );
for( i= 1; i<=nnoduri; i++)
if (ap [i]>= ap[ s]&& cc[ i]== 1){
printf("%d ",i);
cc [i] =0;
}}}




int main( ){
int start;
co1 =0;
citestgraf ();
for (start= 1; start<= nnoduri; start++)
{vi [start]= 0;
cc [start]= 0;
}
for( start= 1 ;start<= nnoduri; start++)
if( vi [start]== 0)
printf("\ n explorare din %d \n", start);
cc [start]= 1;
co1 ++;ap [start]= co1;
er2 (start);
printf("\ n sfarsit explorare");
exit( exitsuccess);
}













djikstra.c
pag 168
prg 10.4

#include "graf.h"
#include "costuri.h"

int cost [nml];

int sel [nmn];

int di[ nmn];
int ta [nmn];

bool id( int su){
int i, arc, nod;
for( i=1;  i<= nno; i++)
di[ i]= 1;
if (!ac( su,& arc))
eroare (eroare lista succesori)
do {if (!an (arc ,&nod))
eroare (eroare aflare nod)
if (nod!= 0){
di[ nod]= cost[ arc];
ta[ nod]= su;
if (!alu (arc ,&arc))
eroare( lega urma)}
while (nod!= 0);
return true;}


bool vfdm( int* k){
int dim ==-1;
int i; 
for (i= 1; i<= nno; i++)
if( di[ i]!=- 1 &&sel[ i]== 0)
if( dim ==-1 ||di[ i]< dim)
{*k= i;
dim= di[ i];}
if (dim ==-1)
eroare (distanta minima)
else
reurn true;}



bool ad (int k){
int arc ,j;
if (!ac( k,& arc)) eroare (aflare adiacente)
do {if (!aflanod (arc ,&j )eroare (aflare nod)
if (j!= 0&& sel[ j] ==0)
if( di[ j]== 1|| di[ j] >di[ k] +cost [arc])
{dis[ j] =dis [k ]+cost [arc];
ta[ j]= k;}
if( j!= 0)
if (!alu (arc,& arc)) eroare (lega urma)}
while( j!= 0);
return true;
}



bool gcm (int s){
int i, k;
sel [s ]=1;
if(! id (s)) return false;
for( i =1 ;i <nno; i++){
if (!vdm (&k)) return false;
sel [k ]=1;
if(! ad( k))
return false;}
return false;}



int main( ){
int i, s;
citestegraf ();
if(! cc ( ))exit (exitfailure)
printf("\ n dati nodul sursa:")
scanf("% d ",sursa);
for( i= 1; i<= nno; i++)
tata[ i ]=0;
sel [i]= 0;}

if (!gcm( s))
exit (exitfailure)
printf("\ n caile minime de la %d au uramtoarele costuri:", s);
for (i =1 ;i <=nno; i++)
if( i!= s)
printf("\ n ->%3d", i)
if (di [i]!=- 1)
printf(" cost %5d cu tatal %5d ",di [i ],ta[ i]);
else
printf("este infinita");}
exit( exitsuccess)}











floyd.c
pag 171
prg 10.6

#include "graf.h"
#include "costuri."

int cost [nml];
int sel [nmn];

int a [nmn  ][nmn];
int p [nmn ][ nmn];

bool iap( ){
int i, j, ij;
for (i =1 ;i <=nn; i++)
for( j= i; j <=nn; j++)
{if (!al( i, j,& ij))
eroare (aflare legatura)
if (ij!= 0)
 a[ i ][ j] =cost [ij];
else
a [i ][j ]=0;
 p[ i ][ j]=0;}}



bool tdm( ){
int i, j, k, ij, ik, kj;
if (!iap ( ))eroare (initializare matrice de lucru)
for( k =1 ;k <=nn; k++)
for( i= 1 ;i<= nn; i++)
if( a[ i][ k]!= 0)
for( j =1 ;j<= nn; j++)
if (i !=j &&a [k ][ j] =0)
if( a[ i  ][j]==0 ||a [i ][ k] +a[ k ][ j]< a[ i ][ j ];
{a[ i][ j] =a [i ][ k] +a [k  ][j]; p[ i ][ j] =k;}}


void c( int j, int j){
int k =p [i ][ j];
if( k!= 0){
c (i, k);
printf(" %d", k);
c (k ,j);
}}



int main( ){
int i ,j;
cg ();
if (!cc( )) exit (exit failure );
if(! tdm ( ))exit (exit failure );
for (i= 1; i<= nn; i++){
printf(" \n costuri minime de la nodul %d sunt:", i);
for( j= 1 ;j <=nn; j++)
if(i!=j){
printf("\n ->%3d cost=", j);
if(a[ i ][ j]!= 0)
{printf("% 5d", a[ i ][ j]);
printf(" calea: %d", i );
if( p [i  ][j ]!=0)
c( i, j);
printf("% d", j);
}else
printf(" inifinit");}}
exit (exit success);}




















p 151
heapsort.C
program 9.8

#include "general.h"
#define nrelem 20
typedef struct{ int key;
...}
elem,* pelem;

typedef bool (*rel)( pelem ,pelem);

elem x [nrele];
int n;


void sch (pelem px ,pelem py){
elem temp;
temp =*px;
*px=* py;
*py =temp;
}


void pro(
pelem t ,int k, int nn, rel r){
int urm;
elem temp;
tem =t[ k];
while ((urm= 2* k)<= nn)
{if ((urm +1 )<nn)
if(!(* r)( &t[ urm],& t[ urm+ 1]))
urm++;
if((* r)(& temp,& t u[rm]))
break;
t [k ]=t [urm];
k =urm;}
t[ k]= temp;}


void hs (pelem px, int n, rel r){
int k, l;
pele xx;
if( n >0){
xx= px- 1;
for( k= (n/ 2); k>= 1; k--)
pro (xx, k ,n ,r );
for (l= n; l> 0;){
sch(& xx[ l] ,&xx[ 1]);
l--;
pro (xx, 1, l, r);
}}}
















krusksel.C
pag 180
prg 10.10


#include "graf.h"
#include "costuri.h"
#include "arbsel.h"

int c [nml];
int s [nml];

int t [nmn];
int cm;
int t [2 ][ nmn];

typedef struct{
int co;
int no1;
int no2;}
mu ,*pmu;

as cp;
bool rcm (p p1, p p2){
ret ((pmu )p1)-> c<= ((pmu) p2)-> c;}


bool acp( ){
int i ,arc, nod;
pmu tmp;
ias (&cp, rcm);
for(i= 1; i<= nn; i++){
if(!ac( i, &arc) err( err lsia tsuccesor)
do
{if(!an( arc,&nod) err (aflare nod)
if(nod !=0)
{if(!(tmp= (pmu)malloc( sizeof(mu)))) err(alocare)
else{
tmp ->c= c[ arc];
tmp ->n1= i;
tmp ->n2= nod;
if(! aias(& cp, tmp)) err (ins coada prioritati)
if(!alu (arc ,&arc)) err( gasire leg urmatoare)}}
while (nod !=0);}
return true;}


bool it(){
int i;
for(i= 1; i<= nn; i++) 
t[ i]=- 1;
return true;
}

bool gc(int i,int* j){
if(i<= 0|| i> nn)
return false;
while( t[ i]> 0)
 i= t[ i];
*j= i;
return true;
}



bool uc(int i,int j){
int k;
if(i= 0|| i> nn|| j<= 0|| j> nn)
return false;
k= t[ i]+ t[ j];
if(t[ i]> t[ j]){
t [i ]=j; t[ j]= k;}
else
{
t [j ]=i ;t [i]= k;}
return true;
}

bool amk( ){
pmu adr;
int i =1;
int w ,u ,cwu;
int cw,cu;
it(!it()) err (init tablou componente)
while(i< nn&& edas(& cp, (pp)& adr)){
w =adr-> n1;
u =adr-> n2;
cwu =adr-> c;
if(! gc( w,& cw)) err (calcula componenta)
if(! gc (u,& cu)) err (calcul componente)
if( cw!= cu){
t[ 0][ i]= w;
t [1 ][ i] =u;
cm+= cwu;
if(! uc( cw, cu))
err (reuniune componente)
i++;}}
if (i< nn- 1)
err (nu exista erbore de acoperire)
else
return true;}



int main( ){
int i ;
cg ();
if(! cg ( ))exit( exitfailure)
for(i= 1; i<= nn ;i++){
s [i]= 0;
t [0 ][ i]= t [1  ][i ]=0;}
cm =0;
if(! acp( )) exit( exitfailure)
if( amk( )) exit (exitfailure)
printf(" \n arbore minim are costul:% d", cm);
printf(" \n muchiiile sunt:") 
for( i= 1 ;i< nn; i++)
printf("\ n %d %d ",t [0 ][ i] ,t [1  ][i] );exit (exitfailure)
}












#define
#include " .h"  < .h> conio.h stdio.h  math.h  stdlib.h iostream.h
#define

 #ifndef
 #ifdef
 #endif

void main(void  argc  argv env){
int ;

if(){;}else{;}
for(;;){;}
do{;}while();
while()do{;};
switch(){
 case :  ;
break;
 default ;
}
printf()
scanf()
cout<<""; cin>>;
exit()

return();



}topsortm.C
pag 156
program 9.9

#include <stdio.h>
#include  <stdlib.h>
#include < string.h> 

#define bool int
#define true 1
#define false 0

#define me unsigned long
#define nemax 32
#define include (e, m) m| =(1l<< e)
#define ei (e ,m ) m =((m| (1l<< e))-( 1l<< e)
#define ap (e, m) (m&( 1l<< e)

int nre ,nrps;
me co [nemax];
int ls[ nemax];

bool ts (int nre ,me *co ,int *ls, int *nrs){
me nes;
bool bl;
int cu ,k;
*nrso= 0;
for( nes= 0, cu=0; cu< nre; include (cu ,nes),
cu++);
do{ bl true;
for( cu= 0; cu< nre; c++){
if (ap( cu, nes) &&!co[ cu]){
bl false;
el( cu, nes);
ls [(*nrs)++]= cu;
if( nes) 
for (k =0; k< nre; elimina (cu, co [k ],k++ );
}}while (!bl&& nes);
return !bl;
}




void cc (void){
int cu ,j;
char li [2];
do {printf("\n re elemente;" ); gets( li );
nrel= atoi( li );
}while ((nrel< 2 ||(nrel> nemax));
printf("\ ncond pentru" );
for( cu= 0; cu< nrel; cu++){ 
printf("\ n elementul %i: \n", cu +1);
do {printf(" ? ");gets( li);
if (!strlen (li))
break;
j =atoi (linie)- 1;
if(( j< 0)||( j>= nemax)||( j== cu))
printf("eroare !\n"); 
else
include (j ,co [cu]);}
while (true );}}




void main( ){
int i;
cico ();
if (ts( nrel, co, ls, &nrpaso))
printf("\ n rezultate sortare topologica: \n");
for (i= 0; i< nrelem;printf(" %i ,ls[ i]+ 1), i++);
}
else
printf(" \ngraf contine cicluri !!\n elemente sortate :\n");
for( i= 0; i< nrpaso ;printf("%i", ls [i ]+1), i++);}
printf("\n");
}









Comentarii

Postări populare de pe acest blog

program principal cpp

#include "clasa.h" #include <stdio.h> #include <conio.h> #include <stdlib.h> #include <string.h> #define DELAY 9000000 void delay() { for(long i=0;i<DELAY;i++); } //constructor cu initializare de la tastatura BigInt::BigInt() {char x; signed char t[400]; int i; printf("\nNumarul cu semn "); do s=getche(); while((s!='+')&&(s!='-')); n=0; do {x=getche(); t[n]=x-'0'; n++; } while((x>='0')&&(x<='9')); n--; for(i=0;i<n;i++) nr[i]=t[n-i-1]; } //constructor cu initializare prin parametri BigInt::BigInt(char semn,signed char numar[],int dim) {int i; s=semn; n=dim; for(i=0;i<n;i++) nr[i]=numar[n-i-1]; } //transform un int negativ in pozitiv int BigInt::Pozitiv(int x) {int a,vb; a=0; vb=0; while(vb==0) if((x+a)==0) vb=1; else a=a+1; x=a; return x; } //constructor dintr-un nr int obisnuit BigInt::BigInt(int x) {int i; if(x>=0) s='+'…

NUMERE PRIME ALGORITM C++

// NUMERE PRIME ALGORITM C++//  reediting from scratch //on this page is just the study for a next algoritm for generating the parime nr series like Fibonnaci or ....if possibile

74111121313417374414124343447 if u know the red part you can generate the orange part
1 0 1 111112222 1 1 23

o aplicatie php localitati romania

//APLICATIA SE REFERA LA BAZA DE DATE SIRUTA

//dragtable.js


/* dragtable v1.0 June 26, 2008 Dan Vanderkam, http://danvk.org/dragtable/ http://code.google.com/p/dragtable/ \Bsortabledraggable\B Instructions: - Download this file - Add <script src="dragtable.js"></script> to your HTML. - Add class="draggable" to any table you might like to reorder. - Drag the headers around to reorder them. This is code was based on: - Stuart Langridge's SortTable (kryogenix.org/code/browser/sorttable) - Mike Hall's draggable class (http://www.brainjar.com/dhtml/drag/) - A discussion of permuting table columns on comp.lang.javascript Licensed under the MIT license. */ // Here's the notice from Mike Hall's draggable script: //***************************************************************************** // Do not remove this notice. // // Copyright 2001 by Mike Hall. // See http…