Wednesday, May 4, 2011

class Node
{
Node next;
int element;
}

class SinglyLinkedList
{
Node head, tail;
int size;
// methods go here
}

Node remove(int value)
{
Node cur = head;
while (cur != null && cur.next != null &&  cur.next.value != value)
cur = cur.next;

cur.next = cur.next.next;
}

void swap(Node x, Node y)
{
int temp;
temp = x.value;
x.value = y.value;
y.value = temp;
}

No comments:

Post a Comment