def insertChild(self, j):
     node = self.children
     if node is None:
         self.children = LinkedNode(j)
     else:
         while node.next != None:
             node = node.next
         node.next = LinkedNode(j)
    def enqueueWaitingList(self, i, k):
        node = self.waiting_list
        if (self.waiting_list == None):
            self.waiting_list = LinkedNode((i, k))
        else:

            while node.next != None:
                node = node.next
            node.next = LinkedNode((i, k))
    def insertResource(self, r, k):
        node = self.resources
        if(node is None):
            self.resources = LinkedNode(value=(r, k),next=None)

        else:
            while node.next != None:
                node = node.next
            node.next = LinkedNode(value=(r,k), next=None)
    def enqueue(self, pid: int, priority: int):

        if (self.readylist[priority] == None):
            self.readylist[priority] = LinkedNode(pid)
        else:
            # loop through that prio level and find the end
            node = self.readylist[priority]
            while node.next != None:
                node = node.next
            node.next = LinkedNode(value=pid, next=None)
Beispiel #5
0
 def __contains__(self, node):
     """
         Searches the linked lists
     :param node: node to the searched
     :return: True if found, False if not found
     """
     new = node if isinstance(node, LinkedNode) else LinkedNode(node)
     return new in self.head
Beispiel #6
0
def insert(value, node=None):
    """
    Insert new value into linked list
    :param value: value of new node in list
    :param node: value of next node
    :return: node: head of linked list
    """

    if node is None:  # if it is first node in linked list return just one node
        return LinkedNode(value, None)

    if node.value >= value:  # if value is less than head node, append to front
        return LinkedNode(value, node)

    node.next_node = insert(value,
                            node.next_node)  # append to back of linked list

    return node
Beispiel #7
0
 def get(self, node):
     """
         Searches for a node in the Linked List
     :param node: node to be searched
     :return: Node if the node is found, else is None
     """
     if self.head:
         new = node if isinstance(node, LinkedNode) else LinkedNode(node)
         return self.head.get(new)
     else:
         return None
Beispiel #8
0
    def add(self, node, lines=None):
        """
            Adds an element to the Linked List
        :param node: node to be added (can also add int)
        :param lines: lines to be added corresponding to the node
        :return: --
        """
        new = node if isinstance(node, LinkedNode) else LinkedNode(
            node, self.substructure(self.substructure))
        if lines:
            for line in lines:
                new.lines.add(line)

        if self.head:
            if new.data < self.head.data:
                new.next = self.head
                self.head = new
            else:
                self.head.add(new)
        else:
            self.head = new
Beispiel #9
0
from LinkedNode import LinkedNode #change this to load in your version of LinkedNode

total = 16
passed = 0

print("Testing object creation")
try:
    node1 = LinkedNode(10)
    if node1.value == 10:
        print("Success!")
        passed += 1
    else:
        print("Test fail. Node1.value should be 10, it is: "+str(node1.value))
except Exception, e:
    print("Test broke.")
    print(e)
    
print("")
print("Testing node linkage")
try:
    node1 = LinkedNode(10)
    node2 = LinkedNode(20, node1)
    if node1.next is node2:
        print("Success!")
        passed += 1
    else:
        print("Test fail. node1.next should be node2 it is: "+str(node1.next))
except Exception, e:
    print("Test broke.")
    print(e)
    
Beispiel #10
0
from LinkedNode import LinkedNode  #change this to load in your version of LinkedNode

total = 16
passed = 0

print("Testing object creation")
try:
    node1 = LinkedNode(10)
    if node1.value == 10:
        print("Success!")
        passed += 1
    else:
        print("Test fail. Node1.value should be 10, it is: " +
              str(node1.value))
except Exception, e:
    print("Test broke.")
    print(e)

print("")
print("Testing node linkage")
try:
    node1 = LinkedNode(10)
    node2 = LinkedNode(20, node1)
    if node1.next is node2:
        print("Success!")
        passed += 1
    else:
        print("Test fail. node1.next should be node2 it is: " +
              str(node1.next))
except Exception, e:
    print("Test broke.")