diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..85e7c1d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/.idea/ diff --git a/datastructures/Python/__init__.py b/datastructures/Python/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/datastructures/Python/linkedlist/Node/__init__.py b/datastructures/Python/linkedlist/Node/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/datastructures/Python/linkedlist/Node/__init__.pyc b/datastructures/Python/linkedlist/Node/__init__.pyc new file mode 100644 index 0000000..3ced3ed Binary files /dev/null and b/datastructures/Python/linkedlist/Node/__init__.pyc differ diff --git a/datastructures/Python/linkedlist/Node/node.py b/datastructures/Python/linkedlist/Node/node.py new file mode 100644 index 0000000..5a1696b --- /dev/null +++ b/datastructures/Python/linkedlist/Node/node.py @@ -0,0 +1,30 @@ +class Node: + data = None + nextNode = None + prevNode = None + + def __init__(self, data=None): + self.data = data + self.nextNode = None + self.prevNode = None + + def setData(self, data): + self.data = data + return self + + def getData(self): + return self.data + + def setNext(self, node=None): + self.nextNode = node + return self + + def getNext(self): + return self.nextNode + + def setPrev(self, node=None): + self.prevNode = node + return self + + def getPrev(self): + return self.prevNode diff --git a/datastructures/Python/linkedlist/Node/node.pyc b/datastructures/Python/linkedlist/Node/node.pyc new file mode 100644 index 0000000..ef10fcf Binary files /dev/null and b/datastructures/Python/linkedlist/Node/node.pyc differ diff --git a/datastructures/Python/linkedlist/__init__.py b/datastructures/Python/linkedlist/__init__.py new file mode 100644 index 0000000..b28b04f --- /dev/null +++ b/datastructures/Python/linkedlist/__init__.py @@ -0,0 +1,3 @@ + + + diff --git a/datastructures/Python/linkedlist/singlyLinkedList.py b/datastructures/Python/linkedlist/singlyLinkedList.py new file mode 100644 index 0000000..8c6ba2d --- /dev/null +++ b/datastructures/Python/linkedlist/singlyLinkedList.py @@ -0,0 +1,58 @@ +from Node.node import Node + +class SinglyLinkedList: + head = None + tail = None + + def __init__(self): + head = None + tail = None + + def addAtEnd(self, node): + if (node==None): + return self + + if (self.head == None): + self.head = node + self.tail = self.head + return self + else: + self.tail.setNext(node) + self.tail = self.tail.getNext(); + + return self + + def addAtBegin(self, node): + if (node==None): + return self + if (self.head == None): + self.head = node + self.tail = self.head + return self + else: + node.setNext(self.head) + self.head = node + + def isEmpty(self): + if (head == None): + return True + else: + return False + + def printList(self): + tmp = self.head + while(tmp!=None): + print tmp.data + tmp = tmp.getNext() + + +s1 = SinglyLinkedList() + +n1 = Node(1) +n2 = Node(2) +n3 = Node(3) +s1.addAtEnd(n1) +s1.addAtEnd(n2) +s1.addAtBegin(n3) + +s1.printList() \ No newline at end of file