Advertisement
Guest User

ARBOL A TODO.h

a guest
Feb 18th, 2020
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. typedef struct Arbol{
  2. char legajo[10];
  3. int horasextras;
  4. struct Arbol *der;
  5. struct Arbol *izq;
  6. }tarbol;
  7.  
  8. struct nodoP{
  9. char leg[10];
  10. int horasextras;
  11. struct nodoP *sig;
  12. }*inicio, *actual;
  13.  
  14. typedef struct listaCircular{
  15. char leg[5];
  16. int horasextras;
  17. struct listaCircular *sig;
  18. }tcirc;
  19.  
  20. void cargaArbol(tarbol **A, char l[],int n){
  21. if (*A==NULL){
  22. *A=malloc(sizeof(tarbol));
  23. (*A)->horasextras=n;
  24. strcpy((*A)->legajo,l);
  25. (*A)->der=NULL;
  26. (*A)->izq=NULL;
  27. }
  28. else{
  29. if (strcmp((*A)->legajo,l)<0){
  30. cargaArbol(&(*A)->izq,l,n);
  31. }
  32. else
  33. cargaArbol(&(*A)->der,l,n);
  34. }
  35. }
  36.  
  37.  
  38. void imprimirpreorder(tarbol *A){
  39. if (A!=NULL){
  40. imprimirpreorder(A->der);
  41. printf("%s %d\n",A->legajo,A->horasextras);
  42. /* push a la pila */
  43. push(A->horasextras);
  44.  
  45. imprimirpreorder(A->izq);
  46.  
  47. }
  48. }
  49.  
  50. tcirc *generaNODOCIR(char l[], int n){
  51. tcirc *aux;
  52. aux=malloc(sizeof(tcirc));
  53. strcpy(aux->leg,l);
  54. aux->horasextras=n;
  55. return aux;
  56. }
  57.  
  58. void cargacircORD(tcirc **LC, char l[], int n){
  59. tcirc *aux,*ant,*act;
  60. aux=generaNODOCIR(l,n);
  61. if (*LC==NULL){
  62. aux->sig=aux;
  63. *LC=aux;
  64. }
  65. else{
  66. if (strcmp((*LC)->leg,aux->leg)>0){
  67. act=*LC;
  68. while(act->sig!=*LC){
  69. act=act->sig;
  70. }
  71. aux->sig=*LC;
  72. act->sig=aux;
  73. *LC=aux;
  74. }
  75. else{
  76. ant=*LC;
  77. act=ant->sig;
  78. while(act!=*LC && strcmp(act->leg,aux->leg)<0){
  79. ant=act;
  80. act=act->sig;
  81. }
  82. ant->sig=aux;
  83. aux->sig=act;
  84. }
  85. }
  86. }
  87.  
  88. int siexsite(tcirc *LC, char l[]){
  89. tcirc *aux;
  90. if (LC!=NULL){
  91. aux=LC;
  92. while(aux->sig!=LC && strcmp(aux->leg,l)!=0){
  93. aux=aux->sig;
  94. }
  95. if (strcmp(aux->leg,l)==0){
  96. return 1;
  97. }
  98. else
  99. return 0;
  100. }
  101. else
  102. return 0;
  103. }
  104.  
  105. // genera Lcirc desdee un arbol
  106. void generalistacirc(tarbol *A, tcirc **LC){
  107. tcirc *aux;
  108. if (A!=NULL){
  109. generalistacirc(A->izq,&(*LC));
  110. generalistacirc(A->der,&(*LC));
  111. if (!siexsite(*LC,A->legajo)){
  112. cargacircORD(&(*LC),A->legajo,A->horasextras);
  113. }
  114. else{
  115. aux=*LC;
  116. while(strcmp(aux->leg,A->legajo)!=0){
  117. aux=aux->sig;
  118. }
  119. aux->horasextras+=A->horasextras;
  120. }
  121. }
  122. }
  123.  
  124.  
  125. void imprimerec(tcirc *LC, tcirc *aux){
  126. if (aux->sig==LC){
  127. printf("leg: %s\thsextr: %d\n",aux->leg,aux->horasextras);
  128. }
  129. else{
  130. printf("leg: %s\thsextr: %d\n",aux->leg,aux->horasextras);
  131. imprimerec(LC,aux->sig);
  132. }
  133. }
  134.  
  135. void ingresadatos(tarbol **A){
  136. int n; char l[10];
  137. printf("leg: ");
  138. fflush(stdin);
  139. gets(l);
  140. printf("nro: ");
  141. scanf("%d",&n);
  142. cargaArbol(&(*A),l,n);
  143. }
  144.  
  145. //----------------------------------------------------------
  146. //----------------------------------------------------------
  147. //-------------------------------//NOSE QUE PARAMETROS LLEVAN
  148. int pila_vacia(){
  149. return (inicio==NULL);
  150. }
  151.  
  152. void push(int n, char l[]){
  153. struct nodoP *nuevo = (struct nodoP *) malloc( sizeof (struct nodoP) );
  154. strcpy(nuevo->leg,l);
  155. nuevo->horasextras = n;
  156. nuevo->sig = NULL;
  157. if (actual==NULL){
  158. actual = nuevo;
  159. inicio = actual;
  160. }
  161. else{
  162. actual->sig = nuevo;
  163. actual = nuevo;
  164. }
  165. }
  166.  
  167. int pop(int n,char l[]){
  168.  
  169. struct nodoP *aux = inicio;
  170. if (inicio==actual){
  171. strcpy(inicio->leg,l);
  172. n = inicio->horasextras=n;
  173. free(inicio);
  174. inicio = NULL;
  175. actual = NULL;
  176. }
  177. else{
  178. aux = inicio;
  179. while (aux->sig!=actual) aux = aux->sig;
  180. n = actual->horasextras=n;
  181. strcpy(inicio->leg,l);
  182. free(actual);
  183. actual = aux;
  184. actual->sig = NULL;
  185. }
  186.  
  187. }
  188.  
  189. void inicializar_pila(){
  190. inicio = NULL;
  191. actual = NULL;
  192. }
  193. /* ME DA ERROR
  194. void vaciar_pila(){
  195. printf("\nVaciando pila ...");
  196. do{
  197. if (inicio!=NULL){
  198. int n = pop();
  199. printf("\npila.pop() = %d", n);
  200. }
  201.  
  202. }
  203. while(!pila_vacia());
  204. printf("\n");
  205. }*/
  206.  
  207. void imprimir()
  208. {
  209. struct nodoP *aux = inicio;
  210. printf("La Pila es: ");
  211. while(inicio!=NULL)
  212. {
  213. printf("%s %d ", inicio->leg, inicio->horasextras);
  214. inicio = inicio->sig;
  215. }
  216. printf("\n");
  217.  
  218. }
  219. //----------------------------------------------------------
  220. //----------------------------------------------------------
  221. //----------------------------------------------------------
  222.  
  223. int menu(){
  224. printf("\n");
  225. system("pause");
  226. system("cls");
  227. printf("1- carga Arbol 2- imp desc 3 - genera lisc 4- Inicializar Pila 5-Mostrar Pila 6 - Vaciar pila 7- Mostrar Lista \n\n");
  228. int op;
  229. scanf("%d",&op);
  230. return op;
  231. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement