Advertisement
Guest User

NUEVO

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