Skip to main content

Posts

Binary Search Tree and Binary Heap in PYTHON

Here is the Python code for Binary Search Tree :- Content included:- 1.) Insertion 2.) Search Operation 3.) Deletion 4.) Minimum Node 5.) Maximum Node 6.) Preorder Traversal 7.) InOrder Traversal 8.) PostOrder Traversal class BST: def __init__(self, data): self.root = data self.left = None self.right =None def insertnode(self, data): if self.root is None: self.root = data return if self.root is data: return elif self.root > data: if self.left is not None: self.left.insertnode(data) else: self.left = BST(data) elif self.root data: if self.left is not None: self.left.searchoprn(data) else: print("Data is not present.") elif self.root self.root: if self.right: selfright = self.right.deletenode(data) ...
Recent posts

Queues in PYTHON

  The Python Code for Queue is here :- class Node: def __init__(self, data): self.data = data self.next = None class Queue: def __init__(self): self.front = self.rear = None def enqueue(self, data): newnode = Node(data) newnode.next = self.rear self.rear = newnode if self.front is None: self.front = newnode def dequeue(self): temp = self.rear while temp.next is not self.front: temp = temp.next self.front = temp temp.next = None def traverse(self): temp = self.rear while temp is not None: print(temp.data, end = " --> ") temp = temp.next print("None") new = Queue() new.enqueue(4) new.enqueue(1) new.enqueue(0) new.enqueue(2) new.traverse() new.dequeue() new.traverse() new.dequeue() new.traverse() 2 --> 0 --> 1 --> 4 --> None 2 --> 0 --> 1 --> None 2 ...

Stacks in PYTHON

  The Python code for Stacks is :- class Stack: def __init__(self): self.top = None def push(self, data): newnode = Node(data) newnode.next = self.top self.top = newnode def pop(self): self.top = self.top.next def traverse(self): temp = self.top while temp is not None: print(temp.data, "--> ", end ="") temp = temp.next print("None") new = Stack() new.push(4) new.push(2) new.push(0) new.traverse() new.pop() new.traverse() 0 --> 2 --> 4 --> None 2 --> 4 --> None So this was the python code and its result of Stacks. Hope you understood the code well. The post will contain the Python code for Queues. Please share it with your friends and help them learning python. John Veer Contact mail id - john.veer.utube@gmail.com Contact us for any query  Thanks for reading ! print("Bye !") www.basicpythonprogramme.blogsp...

Circular Linked List in PYTHON

  So here is the Python code for Circular Linked List :- class Node: def __init__(self,val): self.data = val self.next = None class Clinklist: def __init__(self): self.head = None def insert_begin(self, val): temp = Node(val) temp.next = self.head if self.head is not None: curr = self.head while curr.next is not self.head: curr = curr.next curr.next = temp else: temp.next = temp self.head = temp def printlist(self): curr = self.head if self.head is not None: while curr.next is not self.head: print(curr.data,"->",end=" ") curr = curr.next print(curr.data,"->",end=" ") print("Head") else: print("None") # Insert at end. def insert_end(self, val): if self.head is not None: temp = Node(val) curr = self.head while curr.next != self.head: curr = curr.next ...

Doubly Linked List in PYTHON

  Here is the Python code for the Doubly Linked List :- #first of all creat a class node class Node :     def __init__ ( self , data ):         self . data = data         self . next = None         self . prev = None #now create a class of doubly linked list class DLL :     def __init__ ( self ):         self . head = None #function to insert the node at begining     def insertatbeg ( self , data ):         newnode = Node ( data )         newnode . prev = None         newnode . next = self . head         self . head = newnode #function to insert the node at the end     def insertatend ( self , data ):         newnode = Node ( data )         if self . head is None :             self . head ...

Singly Linked List is PYTHON

  Here is the python code for singly linked list :- #first of all make a node class as given below class Node: def __init__(self, data): self.data = data self.next = None #now create a linkedlist class to insert and delete the nodes class LL: def __init__(self): self.head = None #function to insert the node at begining def insertatbeg(self, data): newnode = Node(data) if self.head is None: self.head = newnode else: newnode.next = self.head self.head = newnode #function to insert the node at last def insertatend(self, data): newnode = Node(data) if self.head is None: self.head = newnode return else: temp = self.head while temp.next is not None: temp = temp.next temp.next = newnode newnode.next = None #function to insert the node at a given position ...

Linked List (For Beginners) Explanation Without Code

Linked List Linked List is a chain of nodes. In which each node contains data and reference of the next node. And that next node contain its own data and reference to the next node. Here reference is considered as address of the next node.  Here we can see the representation of the basic linked list. Here we have the first node contains the data "1" and the the "next " as the reference of the next node. Similarly the second node has its own data "2" and "next" as the reference of the next node. And so on. Here we can the representation of a particular node containing its "data" and "address". And the whole thing is said as a single "NODE" . The reference of the node 2 is stored in the node 1. And the reference of the node 3 is stored in node 2. And so on, but the reference of the first node is called as head. And the reference of the last node is called as tail and considered as "None". Advantages of Linked...