180 likes | 386 Views
Excursie in Romania ( The Land of choice). Elev : Baltoi Ion Costel Marius clasa a X-a A Colegiul National “ Ecaterina Teodoroiu ” Targu-Jiu. Dupa o nunta ca in povesti .
E N D
Excursiein Romania( The Land of choice) Elev: Baltoi Ion Costel Marius clasa a X-a A Colegiul National “EcaterinaTeodoroiu” Targu-Jiu
cei2 indragostiti...El... Student eminent la Ea... Studenta la Facultatea de Facultateade Informatica.... LimbiStraine...
S-au ganditcesafaca in luna de miere...Si s-au razgandit... Dar nu le veneanici o ideebunapentruambiisoti...
Dupamulteframantari, mireluii-a venit o idee...Cearfisameargaintr-o excursie in jurulRomaniei??? Patria sa, locurisipeisajeminunate, oameniospitalieri...
Si gandindu-se el, i s-a parut ca excursiaseamana cu ceva... Dar nu-siamintea cu ce... “Aaa... Astaseamana cu listele de la informaticaaaaa... Imialegtraseul, vizitezlocurilecelemaiapropiate, poatemaiadaugcevalocuripe care le voivizita... Sauvoisterge... Si in final, plecam in excursie...” s-a ganditmirele.
sotia a fost de acord cu planullui, mai ales ca doreasainvetecateceva din liste... Listelecircularedubluinlantuite nu erautocmaigrelepentru ea...
Nimicmaisimplu... El ii explica, ea invata...Cum arputeasaisialeagatraseul??? ...cu ajutoruloperatiei de creare.... Prima data trebuiaudeclaratebiblioteca undesuntincluseinstructiunilecevorfi folosite... #include <iostream.h> #include <string.h> silista... struct{char s[25]; nod*ant, *urm;} *prim, *urm; void creare() {inti; nod*t; prim=new nod; cin.get>>prim->s; prim->urm=0; prim->ant=0; ultim=prim; for (i=1;i<n;i++) {t=new nod; cin.get>>t->s; t->urm-0; t->ant=ultim; ultim->urm=t; ultim=t;} ultim->urm=prim; prim->ant=ultim; }
“Daca ne hotaramsavizitamsialteorase care nu se aflapetraseu, am puteafolosiiinserarea...” void inserare() {char m[20]; nod*t,*p; t=prim; cin.get>>m; if (strcmp(ultim->s,m)==0) {p=new nod; cin.get>>p->s; ultim->urm=p; p->ant=ultim; p->urm=prim; ultim=p;} else {while(strcmp(t->s,m)!=0 && t!=prim) t=t->urm; if (t==prim)cout<<“nu exista”; else{p=new nod; cin>>p->s; p->ant-t; p->urm=t->urm; t->urm->ant=p; t->urm=p;} }}
“Sauputemelimina din orasele de pelista cu ajutorulfunctiei de stergere...” void stergere() {char m[20]; nod*t; cin.get>>m; t=prim; while(strcmp(t->s,m)!=0 && t->urm!=prim) t=t->urm; if (t->urm==prim) cout<<“nu exista”; else {t->ant->urm=t->urm; t->urm->ant=t->ant; delete t;} }
“Vatrebuiacumsasortamcrescator... “ void sortare() {nod*i,*j; char t[20]; i=prim; while(i->urm!=prim) {j=i->urm; while(j!=prim) {if(strcmp(i->s,j->s)>0) {strcpy(t,i->s); strcpy(i->s,j->s); strcpy(j->s,t);}} j=j->urm;} i=i->urm;} }
“Inainte de a pleca in excursie, vatrebuisaafisamlista...” void listare() {nod*p; p=prim; do{ cout<<p->s<<“ “; p=p->urm; while(p!=prim); }
“Am terminat de realizatsubprogramele... Cemairamane de facut??? Aaa... Programul principal in care vomapelafunctiilerealizate anterior... ” int main() {creare();listare(); inserare(); listare(); stergere(); listare(); sortare(); listare(); }
Dupacatevasotuli-a explicatintregulalgoritmsi cum functioneazaacesta, sotia a inceputsainvete... Prima data a scris din noualgoritmul... #include <iostream.h> #include <string.h> struct{char s[25]; nod*ant, *urm;} *prim, *urm; void creare() {inti; nod*t; prim=new nod; cin.get>>prim->s; prim->urm=0; prim->ant=0; ultim=prim; for (i=1;i<n;i++) {t=new nod; cin.get>>t->s; t->urm-0; t->ant=ultim; ultim->urm=t; ultim=t;} ultim->urm=prim; prim->ant=ultim; } void listare() {nod*p; p=prim; do{ cout<<p->s<<“ “; p=p->urm; while(p!=prim);}
void inserare() {char m[20]; nod*t,*p; t=prim; cin.get>>m; if (strcmp(ultim->s,m)==0) {p=new nod; cin.get>>p->s; ultim->urm=p; p->ant=ultim; p->urm=prim; ultim=p;} else {while(strcmp(t->s,m)!=0 && t!=prim) t=t->urm; if (t==prim)cout<<“nu exista”; else{p=new nod; cin>>p->s; p->ant-t; p->urm=t->urm; t->urm->ant=p; t->urm=p;} }} void stergere() {char m[20]; nod*t; cin.get>>m; t=prim; while(strcmp(t->s,m)!=0 && t->urm!=prim) t=t->urm; if (t->urm==prim) cout<<“nu exista”; else {t->ant->urm=t->urm; t->urm->ant=t->ant; delete t;} } void sortare() {nod*i,*j; char t[20]; i=prim; while(i->urm!=prim) {j=i->urm; while(j!=prim) {if(strcmp(i->s,j->s)>0) {strcpy(t,i->s); strcpy(i->s,j->s); strcpy(j->s,t);}} j=j->urm;} i=i->urm;} } int main() {creare(); listare(); inserare(); listare(); stergere(); listare(); sortare(); listare(); }
Dupacevatimp, sotia a terminat de invatatlistele... Sotul, fericit ca a reusitsa ii aratesotieiceva din viitoarealuimeserie, iarsotia era fericita ca a invatatcevanou...
In timpcesotiapregateanecesarulpentruexcursie, sotulpregateanouamasinape care era nerabdatorsa o incerce...