//linkedListLib2.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"linkedListLib2.h" #include"linkedListLib.h" int listSizeTail(node *tail) { int size = 0; while (tail != NULL) { tail = tail->prev; size++; } return size; } void printIntDataHead(node * head) { node * temp = NULL; temp = head; while(temp != NULL) { printf("%d ",temp->data); temp = temp->next; } printf("\n"); } void insert(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 (*head == temp) { temp2 = (node *) malloc (sizeof(node)); temp2->next = *head; (*head)->prev = temp2; *head = (*head)->prev; (*head)->prev = NULL; (*head)->data = data; } else { temp2 = (node *) malloc (sizeof(node)); temp2->next = temp; temp2->prev = temp->prev; temp->prev->next = temp2; temp->prev = temp2; temp2->data = data; } }