Inteligenta_artif&Calcul_paralel_EXEMPLE_C++ (1)

Please download to get full document.

View again

All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
 3
 
  Inteligenta Artificiala
Share
Transcript
  //liste #include <stdio.h>#include <string.h>#include <malloc.h>//structura unui nod / celule / elementtypedef struct NOD{ //NOD numele ales ptr. structuraint id;//.... alte inform. asociate noduluiNOD *urm,*ant; // adresele nodurilor urmator si anteriorNOD;//func!e ptr. crearea unei liste//intoarce adresa capului nodului primul nod din listaNOD* f$creare$lista int n // n nr. de celule alocate{ NOD *caplista,*p,*p%;//p% & adresa nodului anterior for int i'(;i<n;i)) { p' NOD*malloc sieof NOD; memset p,(,sieof NOD;p&>id'i)%;if +i {caplista'p; p%'p;con!nue; p%&>urm'p; p&>ant'p%; p%'p; return caplista; // func!e parcurgere && prelucreaa toate nodurileoid f$parcurgere$prel NOD *caplista{ NOD *p; prin- n;for p'caplista; p; p'p&>urm prin-  &0d&,p&>id; // func!e de parcurgere cu poi!onare pe ul!mul nod//intoarce adresa ul!mului nod din listaNOD* f$po$ul!m$nod NOD *caplista{ NOD *p; for p'caplista;p&>urm;p'p&>urm;   return p; // inserarea in lista dupa un nod dat s// func!a preia nodul din lista dupa care se face inserarea s// si nodul care se insereaa toid f$ins% NOD *s, NOD *t{ if +s&>urm //adaugare { s&>urm't; t&>ant's; return; t&>urm ' s&>urm; // % s&>urm&>ant ' t;// 1 s&>urm ' t;// 2 t&>ant's; // 3 // func!e de poi!onare pe un anumit nod, preia id, si intoarce adresa acestuiaNOD* f$po NOD *caplista, int id{ NOD *p; for p ' caplista; p&>id +' id; p ' p&>urm; if p&>id '' id return p; else return N455;  // inserarea in lista inainte de un nod dat s// func!a preia nodul care se insereaa t// si nodul inaintea caruia se face inserarea soid f$ins1 NOD *t, NOD *s{ t&>ant's&>ant; t&>urm's; s&>ant&>urm't; s&>ant't; // stergere nod, se transmite adresa nodului care a 6 stersoid f$sterge NOD *del{ del&>ant&>urm'del&>urm; if del&>urm del&>urm&>ant'del&>ant; free del;   int main { NOD *7,*y,*;7'f$creare$lista %(;f$parcurgere$prel 7;prin- n 4l!mul nod8;y'f$po$ul!m$nod 7; prin- y.id8 0d,y&>id; //inserare nod dupa    /* ' NOD*malloc sieof NOD; memset ,(,sieof NOD; &>id'%12; y'f$po 7,9;//determina adresa nodului cu id&ul 9 f$ins% y,; f$parcurgere$prel 7; */ //alta inserare inante ' NOD*malloc sieof NOD; memset ,(,sieof NOD; &>id'%13; y'f$po 7,:;//determina adresa nodului cu id&ul : f$ins1 ,y;f$parcurgere$prel 7;    //sterge nod 1    // y'f$po 7,1;f$sterge y; //sau f$sterge f$po 7,1; f$parcurgere$prel 7;return (; //arbori binari #include <stdio.h>#include <malloc.h>#include <string.h>typedef struct NOD{ int id; NOD *st, *dr, *ant;NOD;  NOD* construieste$arore {NOD *p%(=; for int i'(;i<%(;i)) {pi=' NOD*malloc sieof NOD; memset pi=,(,sieof NOD;pi=&>id'i)%; p(=&>st'p%=; p(=&>dr'p1=;p1=&>st'p2=; p1=&>dr'p3=; p2=&>st'p:=;p3=&>st'p=; p3=&>dr'p9=;p=&>st'p?=; p=&>dr'p@=;return p(=;oid parcurge NOD *p{ prin-  nod80d ,p&>id; if p&>st parcurge p&>st; if p&>dr parcurge p&>dr; //prin-  nod80d ,p&>id; return; oid oglinda$ert NOD*p{if p&>st AA p&>dr if p&>st&>id<p&>dr&>id { p&>st&>id'p&>st&>idBp&>dr&>id; p&>dr&>id'p&>st&>idBp&>dr&>id; p&>st&>id'p&>st&>idBp&>dr&>id; prin- rad80d st80d dr80d,p&>id,p&>st&>id, p&>dr&>id;  if p&>st oglinda$ert p&>st; if p&>droglinda$ert p&>dr;int main {NOD *rad'construieste$arore ;    //oglinda$ert rad; parcurge rad; prin- n&&&&&&&&&&//&&&&&&&&&&&&&&&&&&&&&&n;oglinda$ert rad;
Related Search
Similar documents
View more
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks