swap in doubly linked list
问题 I am trying to swap two nodes in a doubly linked list. Below is the part of program having swap function. int swap (int x, int y) { struct node *temp = NULL ; struct node *ptr1, *ptr2; temp = (struct node *)malloc(sizeof(struct node)); if (head == NULL ) { printf("Null Nodes"); } else { ptr1 = ptr2 = head; int count = 1; while (count != x) { ptr1 = ptr1->next; count++; } int count2 = 1; while (count2 != y) { ptr2 = ptr2->next; count2++; } ptr1->next->prev = ptr2; ptr1->prev->next = ptr2; ptr2