Esempio n. 1
0
class Queue:
    def __init__(self):
        self.myList = LinkedList()

    def push(self, data):
        self.myList.append(data)

    def pop(self, data):
        return self.myList.remove_head()
Esempio n. 2
0
    def rotate(self, l, k):

        for i in range(0, k):
            p = l.start
            q = l.start

            while q.next is not None:
                q = q.next

            q.next = p
            temp = p
            p = p.next
            l.start = p
            temp.next = None

        p = l.start
        while p is not None:
            print p.data,
            p = p.next


l = LinkedList()
#l.append(9)
l.append(7)
l.append(6)
l.append(9)
l.append(5)
l.append(1)
l.printlist()

rotateList().rotate(l, 2)
Esempio n. 3
0
                q = q1

        if q:
            p1.next = q

        p = l.start
        while p is not None:
            print p.data,
            p = p.next


l = LinkedList()
#l.append(9)
#l.append(7)
#l.append(6)
l.append(9)
l.append(5)
l.append(1)
l.printlist()

m = LinkedList()
#m.append(9)
#m.append(8)
m.append(8)
m.append(3)
m.append(2)
m.printlist()

mergeSortedList().merge(l, m)

#k.printlist()
Esempio n. 4
0
        while i<(length/2):
            p=p.next
            i+=1
        
        return p.data
    
    #Another Solution
    def middlesoln(self,l):
        p=l.start
        q=l.start

        while q and q.next is not None:
            p=p.next
            q=q.next.next
        
        return p.data
            


l=LinkedList()
l.append(9)
l.append(8)
l.append(6)
l.append(5)
l.append(3)
l.append(2)
l.printlist()

print middleList().middle(l)
print middleList().middlesoln(l)