You are viewing a single comment's thread. Return to all comments →
Node* SortedInsert(Node *head,int data) { // Complete this function // Do not write the main method. struct Node *temp = new Node; struct Node *store = head; temp->data = data; temp->next = NULL; temp->prev = NULL;
if(head == NULL) { return temp; } else { if(data > head->data ) { while((head->next != NULL ) && (data > head->next->data) ) { head = head->next; } if(head->next == NULL) { temp->next = head->next; temp->prev = head; head->next = temp; return store; } temp->next = head->next; temp->prev = head; head->next = temp; temp->next->prev = temp; return store ; } else { temp->next = head; head->prev = temp; return temp; } } return store;
}
Seems like cookies are disabled on this browser, please enable them to open this website
Inserting a Node Into a Sorted Doubly Linked List
You are viewing a single comment's thread. Return to all comments →
Node* SortedInsert(Node *head,int data) { // Complete this function // Do not write the main method. struct Node *temp = new Node; struct Node *store = head; temp->data = data; temp->next = NULL; temp->prev = NULL;
}