You are on page 1of 1

Chapter Problem

Number
Data Structures and Algorithms
Made Easy
Data Structures and Algorithms Made Easy
in Java
Linked
Lists
5 nCurrentElement - NthNode < 0 nCurrentElement - NthNode < 0
Linked
Lists
14 if(loopExists) {
fastPtr = fastPtr->next;
while(slowPtr != fastPtr) {
fastPtr = fastPtr->next;
counter++;
}
return counter;
}
if(loopExists) {
fastPtr = fastPtr.getNext();
while(slowPtr != fastPtr) {
fastPtr = fastPtr.getNext();
counter++;
}
return counter;
}

Linked
Lists
15 struct ListNode *current = head,
temp;
if(!head) return newNode;
while (current != NULL &&
current->data < newNode->data){
temp = current;
current = current->next;
}
newNode->next = current;
temp->next = newNode;
return head;
ListNode current = head;
if(!head) return newNode;
while (current!= NULL &&
current.getData() < newNode.getData()){
temp = current;
current = current.getNext();
}
newNode.setNext(current);
temp.setNext(newNode);
return head;
Linked
Lists
16 struct ListNode *temp = NULL,
*nextNode = NULL;
while (head) {
nextNode = head->next;
head->next = temp;
temp = head;
head = nextNode;
}
return temp;
ListNode temp = NULL, nextNode = NULL;
while ( head ) {
nextNode = head.getNext();
head.setNext(temp);
temp = head;
head = nextNode;
}
return temp;