Beispiel #1
0
def test1():
    mylist = UnorderedList()

    mylist.add(31)
    mylist.add(77)
    mylist.add(17)
    mylist.add(93) 
    mylist.add(26)
    mylist.add(54)

    mylist.search(93)
    mylist.remove(17)

    mylist.remove(31)

    mylist.remove(54)

    mylist.append(9)

    mylist.insert(1,54)

    mylist.insert(0,5)

    mylist.index(4)

    mylist.pop()
    mylist.slice(0,2)
Beispiel #2
0
    def test_2_1(self):
        mylist = UnorderedList()
        numbers = [31, 77, 17, 93, 93, 26, 26, 26, 54, 54, 54]
        for number in numbers:
            mylist.add(number)

        # The linked list should contain 11 items overall
        self.assertEqual(mylist.size(), 11)

        duplicate_results = mylist.find_duplicates()

        # The duplicates should be:
        # 93 occurs a second time
        # 26 occurs a third time
        # 54 occurs a third time
        self.assertEqual(duplicate_results[93], 2)
        self.assertEqual(duplicate_results[26], 3)
        self.assertEqual(duplicate_results[54], 3)

        mylist.remove_duplicates()

        # The size of the Unordered Linked list should be 6
        self.assertEqual(mylist.size(), 6)
        # There should still be an occurrence of every digit:
        # 31, 77, 17, 93, 26, 54
        self.assertTrue(mylist.search(31))
        self.assertTrue(mylist.search(77))
        self.assertTrue(mylist.search(17))
        self.assertTrue(mylist.search(93))
        self.assertTrue(mylist.search(26))
        self.assertTrue(mylist.search(54))

        # There should be no duplicates remaining, running the find_duplicates function
        # should still leave the linkedlist untouched
        mylist.remove_duplicates()
        self.assertEqual(mylist.size(), 6)
Beispiel #3
0
    #print temp, temp.getData()

    myList.add(value)

#exit()

print myList.size()
myList.traversal()
myList.add(99)
myList.add(75)
myList.add(92)

print

myList.search(99)
myList.search(62)

myList.remove(70)
myList.traversal()

myList.remove(99)
myList.traversal()

myList.remove(92)
myList.traversal()

myList.append(5)
myList.append(15)
myList.append(25)
myList.traversal()
# 3.9.1 The Node Class

from node import Node
temp = Node(93)
temp.get_data()

from unorderedList import UnorderedList
my_list = UnorderedList()
my_list.add(31)
my_list.add(77)
my_list.add(17)
my_list.add(93)
my_list.add(26)
my_list.add(54)

my_list.search(17)
my_list.remove(17)
my_list.search(17)
# 3.9.1 The Node Class

from node import Node

temp = Node(93)
temp.get_data()

from unorderedList import UnorderedList

my_list = UnorderedList()
my_list.add(31)
my_list.add(77)
my_list.add(17)
my_list.add(93)
my_list.add(26)
my_list.add(54)

my_list.search(17)
my_list.remove(17)
my_list.search(17)
def unorderedListTest():
	ol = UnorderedList()
	ol.add('A')
	ol.add('B')
	print('a', ol.search('a'))
	print('B', ol.search('B'))