Advertisement
liz28

Untitled

Jan 23rd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.25 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "VenturaLibrary.h"
  5.  
  6.  
  7. Ins* anadirInstruccion(Ins *head , char instruccion[20], int tiempo) //Ins *rootFromMain
  8. {
  9.      int palindromo = strlen(instruccion);
  10.      int x=0;
  11.      for ( x=0; x<palindromo/(2+1); ++x)
  12.      {
  13.        if(instruccion[x] != instruccion[--palindromo])
  14.        {
  15.             printf("NO ES PALINDROMO");
  16.        }
  17.        else
  18.        {
  19.             if(head == NULL) //si no existe la lista, esto es, no hay memoria asignada, se crea el primer elemento 1 sola vez
  20.     {
  21.         head = (Ins *)malloc(sizeof(Ins));
  22.         if(head == NULL) //opcional pero una buena práctica es preguntar si fue posible porque sí hubo memoria disponible
  23.         {
  24.             return NULL; // será la convención (en esta clase) de que no hubo éxito
  25.         }
  26.         strcpy(head->command,instruccion);
  27.         if(tiempo>=5)
  28.         {
  29.           head->tiempo = tiempo;
  30.           head->Next = NULL;
  31.         }
  32.         return head; // 1 será la convención (en esta clase) de que sí hubo éxito
  33.     }
  34.     else //si ya existe el head se estarán agregando (este código es el que se estará ejecutando la mayoría de las veces
  35.     {
  36.         Ins *temporal = (Ins *)malloc(sizeof(Ins));
  37.         Ins *current = head;
  38.         if(temporal == NULL) //opcional pero una buena práctica es preguntar si fue posible porque sí hubo memoria disponible
  39.         {
  40.             return NULL; // será la convención (en esta clase) de que no hubo éxito
  41.         }
  42.  
  43.         strcpy(temporal->command,instruccion);
  44.         if(tiempo>=5)
  45.         {
  46.             temporal->tiempo = tiempo;
  47.             temporal->Next = NULL;
  48.         }
  49.         while(current->Next != NULL) //esto es para ir "caminando" y añadir al final el elemento
  50.         {
  51.             current=current->Next;
  52.         }
  53.         current->Next = temporal;
  54.  
  55.         return head;
  56.     }
  57.    }
  58.   }
  59. }
  60. void recorrer (Ins* head)
  61. {
  62.     Ins *temp = head;
  63.     printf("Recorriendo...\n");
  64.     while(temp) {
  65.       printf("Nombre: %s\n", temp->command);
  66.       printf("Tiempo: %d\n", temp->tiempo);
  67.       temp = temp->Next ;
  68.    }
  69. }
  70.  
  71. Ins* mandarInstrucciones(Ins *head) //en otras palabras, borrar
  72. {
  73.     Ins *temp = head;
  74.     printf("Recorriendo...\n");
  75.     while(temp)
  76.     {
  77.       printf("Borrando{ Nombre: %s\n }\n", temp->command);
  78.       head = temp->Next;
  79.  
  80.       free(temp);
  81.       temp = head;
  82.    }
  83.    return NULL;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement