Dev - C++ - recorrido en arboles binarios

 
Vista:

recorrido en arboles binarios

Publicado por jennifer  (2 intervenciones) el 28/11/2007 17:33:14
hola:
Quiero aprender cual es la implementacion del recorrido infija, posfija y por nivel de arboles en c++ (POO)
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:recorrido en arboles binarios

Publicado por popeye (1 intervención) el 28/11/2007 21:54:21
en google ai miles de documentos relacionado con lo que pides y faciles de buscar.
ees en serio.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:recorrido en arboles binarios

Publicado por Erendira (1 intervención) el 29/12/2008 19:54:34
Quisiera saber como hacerlo tengo una idea pero no se si es buena
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

recorrido en arboles binarios

Publicado por Maria Jose (1 intervención) el 02/01/2009 23:22:42
Ups!! disculpen me pueden ayudar a crear una guia telefonica en dev c++
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

recorrido en arboles binarios

Publicado por yema (1 intervención) el 10/01/2012 21:59:41
aui les dejo la agenda!!!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
# include <stdio.h>
 
# include <string.h>
 
# define FICHERO "datos"
 
# define MAX 25
 
# define ESCAPE ((char)27)
 
FILE *fichero;
 
 
 
struct agenda{				//*************************

	int clave;			//	Esctructura con   *

	char nom[20];			//	la forma de 	  *

	char ApPat[15];			//	los datos registro*

	char ApMat[15];			//*************************

	int edad;

	long int tel;

	long int cel;

	char calle[15];

	char col[15];

	char mun[15];

	char estado[15];

	int sw;

	char mail[25];

}r[MAX];



int  menu (void);

void agregar(void);

void mostrar(struct agenda);

void buscarnom(char[]);

void buscaredad(int);			//********************

void apertura(void);			//Prototipos de las

void m_todo(void);			//	Funciones

void borrar(int);			//********************

void borrartodo(void);

void ordena(void);

void SaveToDisk(struct agenda);

struct agenda ReadToDisk(int);

int ReadAllToDisk(void);

void OrdenaOnMemory(int,int);

void clavesdisponibles(void);

void actualizar(struct agenda,int);

void exportar(void);



int main (){

	int op,opc=0,opcls=0,clave=0,edades=0,i;

	int numreg=0;

	char expresion[20];

	struct agenda reg;
	printf("Creado por Vicente Mendoza");

	apertura();

	menu:

	op = menu();

	switch (op){

		case 1:		

			agregar();					//*********

			goto menu;					//AGREGAR

		break;							//*********

		case 2:

			printf("Dame la clave a borrar: ");

			scanf ("%d",&clave);				//*********

			borrar(clave);					//BORRAR

			printf("tRegistro Borrado: %d",clave);		//*********

			goto menu;

		break;

		case 3:

			printf ("t Como prefiere hacer la busqueda ?");

			printf ("n");

			printf ("tt1. Por Nombre, Apellido Paterno y Materno");

			printf ("n");							//***********

			printf ("tt2. Por Edad");					//BUSQUEDA

			printf("ntOpcion: ");						//***********

			scanf("%d",&opc);

			if(opc==1){

				printf ("Escribe el Nombre o Apellidos a buscar: ");

				scanf  ("%s",expresion);

				buscarnom(expresion);

			}else if(opc=2){

				printf ("Escribe la edad para buscar ");

				scanf  ("%d",&edades);

				buscaredad(edades);

			}

			goto menu;

		break;

		case 4:

			m_todo();		//*************

			goto menu;		//MOSTRAR_TODO

		break;				//*************

		case 5:

			ordena();

			goto menu;

		break;

		case 6:

			printf("n 1)Nombret2)Ap. Paternot3)Ap. Maternot4)Edadt5)Calle");

			printf("nOpcion: ");

			scanf("%d",&opcls);

			numreg=ReadAllToDisk();				//******************

			OrdenaOnMemory(numreg,opcls);			//LISTAR

			for(i=0;i<numreg;i++)				//******************

				mostrar(r[i]);

			goto menu;

		break;

		case 7:

			printf("nQue registro va actualizar (clave): ");

			scanf("%d",&clave);					//***************

			reg=ReadToDisk(clave);					//ACTUALIZAR

			mostrar(reg);						//***************

			printf("nQue dato desea actualizar");

			printf("n 1)Nombret2)Ap. Paternot3)Ap. Maternot4)Edadt5)Callet6)Telefonot7)Celulart8)Email ");

			printf("n Opcion: ");

			scanf("%d",&opcls);

			actualizar(reg,opcls);

			printf("nRegistro Actualizado");

			goto menu;

		break;

		case 8:

			exportar();			//****************

			goto menu;			//EXPORTAR EN CSV

		break;					//****************

		case 9:

			printf("n Ha terminado el programa..n");

		break;

	}

	fclose(fichero);

	return 1;

}

///////////////////////////////////////////////////////////////////////

void ordena(void){

	int i,c;

	c=ReadAllToDisk();

	OrdenaOnMemory(c,1);				//*******************************

	borrartodo();					//Funcion que Ordena el Archivo 

	for(i=0;i<c;i++){				//Por Nombre

		r[i].clave=i+1;				//*******************************

		SaveToDisk(r[i]);

	}

	printf("nArchivo Ordenadon");

}

///////////////////////////////////////////////////////////////////////

void OrdenaOnMemory(int c,int tipo){

	int pas,i;

	struct agenda aux={0};

	for(pas=1;pas<c;pas++)

		for(i=0;i<c-1;i++){

			if(strcmp(r[i].nom,r[i+1].nom)>0 && tipo==1){

				aux=r[i];

				r[i]=r[i+1];						//*******************

				r[i+1]=aux;						//esta funcion

			}else if(strcmp(r[i].ApPat,r[i+1].ApPat)>0 && tipo==2){		//ordena en memoria	

				aux=r[i];						//recibe el numero de

				r[i]=r[i+1];						//registros c

				r[i+1]=aux;						//Y tipo que sirve 

			}else if(strcmp(r[i].ApMat,r[i+1].ApMat)>0 && tipo==3){		//para saber sobre 

				aux=r[i];						//que campo ordenar

				r[i]=r[i+1];						//*******************

				r[i+1]=aux;			

			}else if(r[i].edad >= r[i+1].edad && tipo==4){

				aux=r[i];

				r[i]=r[i+1];

				r[i+1]=aux;			

			}else if(strcmp(r[i].calle,r[i+1].calle)>0 && tipo==5){

				aux=r[i];

				r[i]=r[i+1];

				r[i+1]=aux;			

			}

		}	

}

///////////////////////////////////////////////////////////////////////

void apertura(void){						//*********************************

	if((fichero=fopen(FICHERO,"r+"))==NULL)			//Metodo para abrir el archivo

		fichero=fopen(FICHERO,"w");			//En caso de error crea el archivo

}								//*********************************

///////////////////////////////////////////////////////////////////////

int menu(void){

	int opmenu=0;

	printf("%c[1;34m",ESCAPE);				//*********************************

	printf ("ntM E N U");					//Fucion que muestra el Menu

	printf("n");						//retorna un entero con el valor

	printf("%c[2;36m",ESCAPE);				//de la opcion elegida

	printf ("1)Agregar");					//*********************************

	printf (" 2)Borrar");

	printf (" 3)Buscar");

	printf (" 4)M.Todo");

	printf (" 5)OrdenarArchivo");

	printf (" 6)Listar");

	printf (" 7)Modificar Registro");

	printf (" 8)Exportar");

	printf (" 9)Salir");

	printf ("n");

	printf ("Opcion: ");

	scanf("%d",&opmenu);

	printf("%c[0m",ESCAPE);

	return opmenu;

}

///////////////////////////////////////////////////////////////////////

void SaveToDisk(struct agenda registro){				//****************************************

	fseek(fichero,(registro.clave-1)*sizeof(registro),SEEK_SET);	//Funcion para Salvar 1 registro en disco

	fwrite(®istro,sizeof(registro),1,fichero);			//recibe el registro y lo guarda dependiendo de su

}									//clave en el archivo

//////////////////////////////////////////////////////////////////////  //**********************************************

void agregar(void){

	int clave;

	struct agenda registro,aux;

	printf("%c[31m",ESCAPE);

	clavesdisponibles();

	printf("%c[0m",ESCAPE);

	do{

		printf (" Dame tu clave: ");				//******************************

		scanf  ("%d",&clave);					//Codigo para validar la clave

		if(clave>MAX) {						//debe de ser menor que MAX

			printf("%c[31m",ESCAPE);			//Y no puede usar una con datos

			printf("Tu clave debe ser menor que %dn",MAX);	//asociados

			printf("%c[0m",ESCAPE);				//******************************

		}

		aux=ReadToDisk(clave);

		if(aux.sw==1){

			printf("%c[31m",ESCAPE);

			printf("La clave ya esta en uso n");

			printf("%c[0m",ESCAPE);

		}

	}while(clave>MAX || aux.sw==1);

	registro.clave=clave;

	printf (" Cual es tu nombre ? ");				//****************************** 

	scanf  ("%s",registro.nom);					//Metodo para Pedir datos

	printf (" Cual es tu Apellido Paterno ? ");			//y despues agregarlos a disco

	scanf  ("%s",registro.ApPat);					//******************************

	printf (" Cual es tu Apellido Materno ? ");

	scanf  ("%s",registro.ApMat);

	printf (" Cual es tu edad ? ");

	scanf  ("%d",®istro.edad);

	printf (" Cual es tu telefono ? ");

	scanf  ("%ld",®istro.tel);

	printf (" Cual es tu telefono celular? ");

	scanf  ("%ld",®istro.cel);

	printf (" Cual es tu calle ? ");

	scanf  ("%s",registro.calle);

	printf (" Cual es tu colonia ? ");

	scanf  ("%s",registro.col);

	printf (" Cual es tu Municipio ? ");

	scanf  ("%s",registro.mun);

	printf (" En que Estado vives ? ");

	scanf  ("%s",registro.estado);

	printf (" Cual es tu e-mail ? ");

	scanf  ("%s",registro.mail);

	registro.sw=1;

	SaveToDisk(registro);

	printf ("Se ha agregado otro elemento a la agenda");

}

///////////////////////////////////////////////////////////////////////

void buscarnom(char expresion[20]){				//************************************		

	int i=2;						//Funcion que sirve para buscar una expresion (NOMBRE)

	struct agenda registro;					//en todos los registros.

	registro = ReadToDisk(1);				//************************************

	do{

		if((strcmp(registro.nom,expresion))==0 || (strcmp(registro.ApPat,expresion))==0 || (strcmp(registro.ApMat,expresion))==0)

			mostrar(registro);

		registro=ReadToDisk(i);

		i++;

	}while(!feof(fichero));

}

///////////////////////////////////////////////////////////////////////

void buscaredad(int edades){

	int i=2;

	struct agenda registro;						//*********************************

	registro=ReadToDisk(1);						//Funcion que sirve para buscar

	do{								//una edad en todos los registros

		if(registro.edad == edades)				//*********************************

			mostrar(registro);

		registro=ReadToDisk(i);

		i++;

	}while(!feof(fichero));

}

///////////////////////////////////////////////////////////////////////

int ReadAllToDisk(void){

	struct agenda registro;

	int i=2,c=0;

	registro=ReadToDisk(1);

	do{

		if(registro.sw==1){				//*************************************

			r[c]=registro;				//Funcion que lee todos los registros

			c++;					//del archivo 

		}						//*************************************

		registro=ReadToDisk(i);

		i++;

	}while(!feof(fichero));

	return c;

}

///////////////////////////////////////////////////////////////////////

struct agenda ReadToDisk(int clave){

	struct agenda registro;					//*********************************************

	fseek(fichero,(clave-1)*sizeof(registro),SEEK_SET);	//funcion que recibe una clave ,se diige a ella

	fread(®istro,sizeof(registro),1,fichero);		//en el archivo la lee y retorna la estructura

	return registro;					//*********************************************

}

///////////////////////////////////////////////////////////////////////

void m_todo(void){

	int i=2;

	struct agenda registro;

	registro=ReadToDisk(1);				//**************************

	do{						//Metodo para mostrar todos

		if(registro.sw==1)			//los registros del archivo

			mostrar(registro);		//***************************

		registro=ReadToDisk(i);

		i++;

	}while(!feof(fichero));

}

///////////////////////////////////////////////////////////////////////

void mostrar(struct agenda registro){

	printf ("n");

	printf (" Clave: tt %d ",registro.clave);

	printf ("n");

	printf (" Nombre: tt %s",registro.nom);

	printf ("n");

	printf (" Apellido Paterno: t %s",registro.ApPat);

	printf ("n");

	printf (" Apellido Materno: t %s",registro.ApMat);	//*******************************

	printf ("n");						//Funcion que recibe un registro

	printf (" Edad: ttt %d",registro.edad);		//y muestra sus campos

	printf ("n");						//*******************************

	printf (" Telefono: tt %ld",registro.tel);

	printf ("n");

	printf (" Telefono Celular:t %ld",registro.cel);

	printf ("n");

	printf (" Calle: tt %s",registro.calle);

	printf ("n");

	printf (" Colonia: tt %s",registro.col);

	printf ("n");

	printf (" Municipio: tt %s",registro.mun);

	printf ("n");

	printf (" Estado: tt %s",registro.estado);

	printf ("n");

	printf (" Mail: ttt %s",registro.mail);

	printf ("n");

	sleep(1);

}

///////////////////////////////////////////////////////////////////////

void borrar(int clave){

	struct agenda aux={0,"","","",0,0,0,"","","","",0,""};		//******************************

	fseek (fichero,(clave-1)*sizeof(aux),SEEK_SET);			//Funcion que guarda un registro

	fwrite(&aux,sizeof(aux),1,fichero);				//vacio para borrar el anterior

}									//******************************

///////////////////////////////////////////////////////////////////////

void borrartodo(void){

int i;						//*****************************

for (i=1;i<=MAX;i++)				//Metodo que deja el Archivo	

	borrar(i);				//en blanco (borra todo)

}						//*****************************

///////////////////////////////////////////////////////////////////////

void clavesdisponibles(void){

	struct agenda registro;

	int i=2;

	registro=ReadToDisk(1);

	printf("Las claves disponibles son: ");			//***********************

	do{							//Metodo que visualiza

		if(registro.sw!=1)				//todas las claves 

			printf("%d ",i-1);			//disponibles

		registro=ReadToDisk(i);				//***********************

		i++;

	}while(!feof(fichero));

	for(;i<=MAX+1;i++)

		printf("%d ",i-1);

	printf("n");

}

///////////////////////////////////////////////////////////////////////

void actualizar(struct agenda registro,int opcion){

	switch(opcion){

		case 1:

			printf (" Nombre ? ");

			scanf  ("%s",registro.nom);

		break;

		case 2:

			printf (" Apellido Paterno ? ");

			scanf  ("%s",registro.ApPat);

		break;						//**********************************

		case 3:						//Funcion que recibe un registro 

			printf (" Apellido Materno ? ");	//y modifica segun "opcion"

			scanf  ("%s",registro.ApMat);		//el campo correspondiente

		break;						//**********************************

		case 4:

			printf (" Edad ? ");

			scanf  ("%d",®istro.edad);

		break;

		case 5:

			printf (" Calle ? ");

			scanf  ("%s",registro.calle);

		break;

		case 6:

			printf (" Telefono ? ");

			scanf  ("%ld",®istro.tel);

		break;

		case 7:

			printf (" Telefono celular? ");

			scanf  ("%ld",®istro.cel);

		break;

		case 8:

			printf (" Cual es tu e-mail ? ");

			scanf  ("%s",registro.mail);

		break;

	}

	SaveToDisk(registro);

}

///////////////////////////////////////////////////////////////////////

void exportar(void){

	FILE *archivo;

	char nombre[20];				//********************************

	int c,i;					//Metodo que sirve para 

	c=ReadAllToDisk();				//crear un archivo de texto

	OrdenaOnMemory(c,1);				//con valores separados por comas

	printf("Nombre del Archivo: ");			//********************************

	scanf("%s",nombre);

	if((archivo=fopen(nombre,"w"))==NULL)

		archivo=fopen(nombre,"w");

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

		fprintf(archivo,"%d,%s,%s,%s,%d,%d,%d,%s,%s,%s,%s,%s,n",r[i].clave,r[i].nom,r[i].ApPat,r[i].ApMat,r[i].edad,r[i].tel,r[i].cel,r[i].calle,r[i].col,r[i].mun,r[i].estado,r[i].mail);

	fclose(archivo);

}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar