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
- {
- 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
- }
- palindromo(instruccion, tiempo);
- strcpy(head->command,instruccion);
- 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
- }
- palindromo(instruccion,tiempo);
- strcpy(temporal->command,instruccion);
- 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;
- }
- void palindromo(char instruccion[20], int tiempo){
- char reves[30];
- strcpy(reves,instruccion);
- strrev(reves);
- int a=0;
- for(int i=0;i<strlen(instruccion);i++){
- if(instruccion[i]==reves[i]){
- a++;
- if(a==strlen(instruccion)){
- if(tiempo>5){
- return 0;
- }else{
- exit(1);
- }
- }
- }else{
- exit(1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement