Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <conio.h>
- #include <string.h>
- #include "LinkedListFuncs.h"
- void initList(List * l) {
- *l = NULL;
- }
- Boolean VerifyEmptyList(List l) {
- return (l == NULL) ? TRUE : FALSE;
- }
- ListNode* NewNode(void* data) {
- ListNode* newNode = (ListNode*)malloc(sizeof(ListNode));
- if (newNode) {
- newNode->next = NULL;
- newNode->pData = data;
- }
- return(newNode);
- }
- ListNode* NewNode() {
- ListNode* newNode = (ListNode*)malloc(sizeof(ListNode));
- if (newNode) {
- newNode->next = NULL;
- newNode->pData = NULL;
- }
- return(newNode);
- }
- Status InsertIni(List* l, void* data) {
- ListNode* newNode = NewNode(data);
- if (newNode != NULL) {
- newNode->next = *l;
- *l = newNode;
- return OK;
- }
- return ERROR;
- }
- Status InsertEnd(List* l, void* data) {
- ListNode* newNode = NewNode(data), *auxNode;
- void* s = newNode->pData;
- if (newNode != NULL) {
- if (*l == NULL) {
- *l = newNode;
- }
- else {
- auxNode = *l;
- while (auxNode != NULL) {
- if (auxNode->next == NULL) {
- auxNode->next = newNode;
- return OK;
- }
- else {
- auxNode = auxNode->next;
- }
- }
- }
- }
- return ERROR;
- }
- int ListSize(List l) {
- int count = 0;
- while (l != NULL) {
- count++;
- l = l->next;
- }
- return count;
- }
- void PrintNodes(List l, char*(*f)(void* data)) {
- if (VerifyEmptyList(l) == TRUE) {
- printf("\nThe list is empty!\n");
- return;
- }
- while (l != NULL) {
- char* funcRet = f(l->pData);
- printf("\n%s", funcRet);
- free(funcRet);
- l = l->next;
- }
- }List findPreviousNode(List l, List node) {
- List aux = l;
- while (l != NULL) {
- if (l->next == node) {
- return l;
- }
- else {
- l = l->next;
- }
- }
- return NULL;
- }
- void removeNode(List* l, List prevNode, List nodeRm) {
- ListNode* adressAux = nodeRm->next;
- List* listAux = l;
- while (l != NULL) {
- if (*l == nodeRm) {
- free((*l)->pData);
- free(l);
- break;
- }
- else {
- *l = (*l)->next;
- }
- }
- l = listAux;
- while (l != NULL) {
- if (*l == prevNode) {
- prevNode->next = adressAux;
- break;
- }
- else {
- (*l) = (*l)->next;
- }
- }
- }
- //
- //Apagar elementos da lista :
- //
- //aux = L;
- //while (aux != NULL) {
- // naux = aux->next;
- // free(aux->data);
- // free(aux);
- // aux = naux;
- //}
- //L = NULL;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement