Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include "list.h"
- void initList(TList* l){
- l->start = NULL;
- l->end = NULL;
- l->nElem = 0;
- }
- void finalizeList(TList* l){
- TNode *n = l->start;
- TNode *aux;
- while(n != NULL){
- aux = n;
- n = n->next;
- free(aux);
- }
- }
- void insertList(TList* l, TInfo x){
- TNode *n = malloc(sizeof(TNode));
- n->value = x;
- n->next = NULL;
- if(isEmptyList(l)){
- l->start = n;
- l->end = n;
- }else{
- l->end->next = n;
- l->end = n;
- }
- l->nElem++;
- }
- void deleteList(TList *l, TInfo x){
- TNode *n = l->start;
- TNode *p;
- if(!isEmptyList(l)){
- if(n->value == x){
- p = n;
- n = n->next;
- free(p);
- l->start = n;
- l->nElem--;
- }else{
- while(n->next !=NULL && n->value != x){
- p = n;
- n = n->next;
- }
- if(n->value == x){
- if(n->next == NULL)
- l->end = p;
- p->next = n->next;
- free(n);
- l->nElem--;
- }
- }
- }
- }
- void printList(TList *l){
- TNode *n = l->start;
- while(n != NULL){
- printf("%d ",n->value);
- n = n->next;
- }
- printf("\n");
- }
- int isEmptyList(TList *l){
- if(l->start == NULL)
- return 1;
- return 0;
- }
- int sizeList(TList *l){
- return l->nElem;
- }
- int memberList(TList* l, TInfo x){
- TNode *n = l->start;
- while(n != NULL){
- if(n->value == x)
- return 1;
- n = n->next;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment