- Tree
- Set
- Array
- Linked List
public static Node reverseLinkedList(Node current) {
Node prev = null;
Node next;
while (current != null) {
next = current.next;
current.next = prev;
prev = current;
prev.next = current;
current = next;
}
return prev;
}
prev.next = current;
current.next = prev;
prev = current;
current = next;
int i = 4;
int j = 1;
int k = 0;
for (i = 0; i < 3; i++) {
k += j;
j = 1 - j;
}
- 5
- 4
- 1
- 2
int mystery(int n) {
if (n == 0) return 0;
if (n == 1) return 1;
return mystery(n-1) + mystery(n-2);
}
- O(1)
- O(n)
- O(mystery)
- O(2^n)
def mystery(alist):
for index in range(1, len(alist)):
pos = index
current = alist[index]
while pos > 0 and alist[pos-1] > current:
alist[pos] = alist[pos-1]
pos = pos - 1
alist[pos] = current
- reverses list
- does nothing
- sorts list
- removes smallest element from alist
-
?
-
?
-
?
-
?
-
?