Tuesday, September 27, 2011
lecture
function removeLast(): # DLinkedList with trailer
if size = 0:
error!
lastElem = tail.prev
lastElem.prev.next = lastElem.next # or, tail
lastElem.next.prev = lastElem.prev
size--
function removeLast(): # DLinkedList without trailer
if size = 0:
error!
else if size = 1:
head = tail = null
size--
else:
tail = tail.prev
tail.next = null
size--
function insertFront(elem x): # DLinkedList with header
n = new Node(x)
oldFirstNode = head.next
head.next = n
n.prev = head
oldFirstNode.prev = n
n.next = oldFirstNode
size++
/*
# their way, v being the new node n
w = head.next
v.next = w
v.prev = head
w.prev = v
head.next = v
size++
*/
function insertFront(elem x): # DLinkedList without header and trailer
n = new Node(x)
if size = 0:
head = tail = n
else:
n.next = head
head = n
n.prev = null
n.next.prev = n
size++
An "interesting" situation. We have DNodes and Dlists.
DNodes have getNext() and getPrev()
DLists have getNext(DNode n) and getPrev(DNode n)
procedure based
DNode getPrev(Dnode n)
{
}
object oriented programming
n.getPrev()
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment