1 回答

TA贡献1846条经验 获得超7个赞
// Our nodes will consist of 3 cells in each object.
// key = a number (int)
// prev = address pointer to previous node
// next = address pointer til next node
// This function creates an empty list
function emptyList()
L = new List{head = nil, size = 0}
return L
// This function creates a node.
function makeNode(val)
node = new Node{prev = NIL, key = val, next = NIL}
return node
// This function inserts n amount of nodes to an empty list
function InsertNodes(n)
// Create an empty list, S.
emptyList()
// Initiate the first node
S.head = makeNode(1)
//tail keeps the last node
tail = head
for i = 2 to n
tail.next = makeNode(i)
tail.next.prev = tail
tail = tail.next
添加回答
举报