def getSlice(MLL, first, last):
    #  a function validating input params should be added later on
    current = MLL.head
    while current != first:
        current = current.getNext()
    sliceLL = UnorderedList()
    while current != last.getNext():
        sliceLL.append(current.getData())
        current = current.getNext()
    return sliceLL
 def test_append(self):
     ulist = UnorderedList()
     ulist.append(1)
     self.assertEqual(ulist.head.data, 1)
     ulist.append(2)
     self.assertEqual(ulist.head.next.data, 2)
     ulist.append(3)
     self.assertEqual(ulist.head.next.next.data, 3)
 def test_insert(self):
     ulist = UnorderedList()
     ulist.insert(0, 0)
     self.assertEqual(ulist.head.data, 0)
     self.assertEqual(ulist.head.getNext(), None)
     ulist.insert(1, 1)
     # self.assertEqual(ulist.head.getNext(), None)
     self.assertEqual(ulist.head.getNext().data, 1)
コード例 #4
0
ファイル: main.py プロジェクト: Pepper-Wood/AdventOfCode
def spinlockLinkedList(stepNum):
    states = UnorderedList()
    states.append(0)
    statesSize = 1
    currentPos = 0
    stateNum = 1
    while stateNum < 10:
        currentPos += stepNum
        currentPos %= statesSize
        currentPos += 1
        print "Inserting into " + str(currentPos)
        if statesSize == 1:
            states.append(stateNum)
        else:
            states.insert(currentPos, stateNum)
        statesSize += 1
        stateNum += 1
        print states
import UnorderedList

#===========================================================================
# create a linked list to test MergeSort()
myList = UnorderedList()
myList.add(13)
myList.add(38)
myList.add(50)
myList.add(14)
myList.add(45)
myList.add(27)
myList.append(70)
myList.insert(4, 48)

#===========================================================================
# define a function to return a sliced linked list given the startnode and endnode
def getSlice(MLL, first, last):
    #  a function validating input params should be added later on
    current = MLL.head
    while current != first:
        current = current.getNext()
    sliceLL = UnorderedList()
    while current != last.getNext():
        sliceLL.append(current.getData())
        current = current.getNext()
    return sliceLL

# define a function to return the midnode between the startnode and endnode
def getMid(MLL, first, last):
    #  a function validating input params should be added later on
    current = MLL.head
 def test_pop(self):
     ulist = UnorderedList()
     ulist.append(0)
     ulist.append(1)
     ulist.append(2)
     self.assertEqual(ulist.pop(2), 2)
 def test_index(self):
     ulist = UnorderedList()
     ulist.append(0)
     self.assertEqual(ulist.index(0), 0)
     ulist.append(1)
     self.assertEqual(ulist.index(1), 1)
 def test_remove(self):
     ulist = UnorderedList()
     ulist.add(1)
     ulist.remove(1)
     self.assertEqual(ulist.isEmpty(), True)
 def test_search(self):
     ulist = UnorderedList()
     ulist.add(1)
     self.assertEqual(ulist.head.data, 1)
     self.assertEqual(ulist.head.next, None)
     self.assertEqual(ulist.search(1), True)
 def test_size(self):
     ulist = UnorderedList()
     ulist.add(1)
     self.assertEqual(ulist.size(), 1)
 def test_add(self):
     ulist = UnorderedList()
     ulist.add(1)
     self.assertEqual(ulist.isEmpty(), False)
     self.assertEqual(ulist.head.getNext(), None)
 def test_isEmpty(self):
     ulist = UnorderedList()
     self.assertEqual(ulist.isEmpty(), True)
 def test_init(self):
     ulist = UnorderedList()