-
Notifications
You must be signed in to change notification settings - Fork 0
/
Problem2.1
46 lines (34 loc) · 1005 Bytes
/
Problem2.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/*******************************************************
Program Number: 1a
Author: Nicolas Dabdoub
Purpose/Description: Swap two adjacent elements using only the links(single linked lists)
Due date: <02/28/15>
Certification:
I hereby certify that this work is my own and none of it is the
work of any other person.
< Nicolas Daboub>
*******************************************************/
// beforep is the cell before the two adjacent cells that are to be swapped.
public static void swapWithNext( Node beforep )
{
Node p, afterp;
p = beforep.next;
afterp = p.next;
p.next = afterp.next;
afterp = beforep.next;
beforep.next = afterp;
}
Problem 1b
// p and afterp are cells to be switched.
public static void swapWithNext( Node p )
{
Node beforep, afterp;
p = beforep.next;
afterp = p.next;
p.next = afterp.next;
afterp.next = p;
beforep.next = afterp;
afterp.prev = beforep;
p.prev = afterp;
p.next.prev = p;
}