Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "VenturaLibrary.h"
- Ins* anadirInstruccion(Ins *head , char instruccion[20], int tiempo) //Ins *rootFromMain
- {
- int palindromo = strlen(instruccion);
- int x=0;
- for ( x=0; x<palindromo/(2+1); ++x)
- {
- if(instruccion[x] != instruccion[--palindromo])
- {
- printf("NO ES PALINDROMO");
- }
- else
- {
- if(head == NULL) //si no existe la lista, esto es, no hay memoria asignada, se crea el primer elemento 1 sola vez
- {
- head = (Ins *)malloc(sizeof(Ins));
- if(head == NULL) //opcional pero una buena práctica es preguntar si fue posible porque sí hubo memoria disponible
- {
- return NULL; // será la convención (en esta clase) de que no hubo éxito
- }
- strcpy(head->command,instruccion);
- if(tiempo>=5)
- {
- head->tiempo = tiempo;
- head->Next = NULL;
- }
- return head; // 1 será la convención (en esta clase) de que sí hubo éxito
- }
- 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
- {
- Ins *temporal = (Ins *)malloc(sizeof(Ins));
- Ins *current = head;
- if(temporal == NULL) //opcional pero una buena práctica es preguntar si fue posible porque sí hubo memoria disponible
- {
- return NULL; // será la convención (en esta clase) de que no hubo éxito
- }
- strcpy(temporal->command,instruccion);
- if(tiempo>=5)
- {
- temporal->tiempo = tiempo;
- temporal->Next = NULL;
- }
- while(current->Next != NULL) //esto es para ir "caminando" y añadir al final el elemento
- {
- current=current->Next;
- }
- current->Next = temporal;
- return head;
- }
- }
- }
- }
- void recorrer (Ins* head)
- {
- Ins *temp = head;
- printf("Recorriendo...\n");
- while(temp) {
- printf("Nombre: %s\n", temp->command);
- printf("Tiempo: %d\n", temp->tiempo);
- temp = temp->Next ;
- }
- }
- Ins* mandarInstrucciones(Ins *head) //en otras palabras, borrar
- {
- Ins *temp = head;
- printf("Recorriendo...\n");
- while(temp)
- {
- printf("Borrando{ Nombre: %s\n }\n", temp->command);
- head = temp->Next;
- free(temp);
- temp = head;
- }
- return NULL;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement