Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include "listaC.h"
- void crearLista(TListaC *lc){
- lc->first = NULL;
- lc->elem = 0;
- lc->last = NULL;
- }
- void insertar(TListaC *lc, TInfo x){
- TNode *node = malloc(sizeof(TNode));
- strcpy(node->info,x);
- if(lc->elem == 0){
- lc->first = node;
- lc->last = node;
- node->next = node;
- }else{
- node->next = lc->first;
- lc->last->next = node;
- lc->last = node;
- }
- lc->elem++;
- }
- void printList(TListaC *lc){
- TNode *ptr = lc->first;
- int i;
- while(ptr != lc->last){
- for(i=0; i<strlen(ptr->info); i++)
- printf("%c",ptr->info[i]);
- printf("\n");
- ptr = ptr->next;
- }
- for(i=0; i<strlen(ptr->info); i++)
- printf("%c",ptr->info[i]);
- printf("\n");
- }
- void mueranTodos(TListaC *lc, TInfo x, int k){
- int count = 0;
- TNode *ptr = lc->first;
- TNode *aux;
- if(lc->elem == 0)
- return;
- while(strcmp(ptr->info,x) != 0)
- ptr = ptr->next;
- int i;
- int n = lc->elem;
- for(count = 0; count < n-1; count++){
- for(i=0; i<k-1; i++)
- ptr = ptr->next;
- if(ptr->next == lc->first)
- lc->first = ptr;
- if(ptr->next == lc->last)
- lc->last = ptr;
- ptr->next = ptr->next->next;
- lc->elem--;
- if(lc->elem != 1)
- ptr = ptr->next;
- }
- for(int i=0; i<strlen(ptr->info); i++)
- printf("%c",ptr->info[i]);
- printf("\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement