//linkedListLib3.c //John T. Rine //October 6, 2011 //lab46:~$ gcc -c linkedListLib.c -o linkedListLib.o //lab46:~$ ar crs liblinkedListLib.a linkedListLib.o //lab46:~$ gcc -I. linkedListTest.c -o linkedListTest liblinkedListLib.a #include #include //#include"linkedListLib3.h" #include"linkedListLib.h" void append(node **head, node **tail, int position, int data) { int i; node *temp, *temp2; temp = temp2 = NULL; temp = *head; for(i = 0; i < position; i++) { temp = temp -> next; } if (*head == NULL) { *head = (node *) malloc(sizeof(node)); *tail = *head; (*head)->prev = NULL; (*head)->next = NULL; (*head)->data = data; } else if (*tail == temp) { temp2 = (node *) malloc (sizeof(node)); temp2->prev = *tail; temp2->next = NULL; (*tail)->next = temp2; *tail = temp2; (*tail)->data = data; } else { temp2 = (node *) malloc (sizeof(node)); temp2->prev = temp; temp2->next = temp->next; temp->next->prev = temp2; temp->next = temp2; temp2->data = data; } } void deleteNode(node **head, node **tail, int position) { int i; node * temp = NULL; temp = *head; for(i = 0; i < position; i++) { temp = temp->next; } if(temp != *head && temp != *tail) { temp->next->prev = temp->prev; temp->prev->next = temp->next; temp->prev = NULL; temp->next = NULL; } else if (temp == *head) { temp->next->prev = NULL; *head = temp->next; temp->next = NULL; } else { temp->prev->next = NULL; *tail = temp->prev; temp->prev = NULL; } free(temp); } void loadListData(node *head) { int i = 0; node *temp = NULL; temp = head; printf("Enter a value or -1 to quit: "); scanf("%d", &i); while(i != -1) { temp->data = i; temp = temp->next; if(temp == NULL) { printf("List is full of data!\n"); break; } printf("Enter a value or -1 to quit: "); scanf("%d", &i); } }