Posts

Showing posts from November, 2022

Single Linked list python program code

# This are commets if you don't write also no issues # Linked Lists # We are only given the head of the linked list. # Make a Linked List Node Class class Node(object): # Constructor def __init__(self,data): self.data = data # Data to be stored self.nextNode = None # Pointer to next Node; Initialized to "None" # Linked List head (root node) and size class LinkedList(object): def __init__(self): self.head = None # head -> first node in Linked List; initially "None" self.size = 0 # Initial size of Linked List # ------------------ Insertion at Starting of Linked List ----------------- # Insert a New Node to starting of Linked List # O(1) time Complexity def insertStart(self,data): self.size += 1 # Increment the size of Linked List by 1 newNode = Node(data)

Development cycle python

Features Of Python ! Important question for pp

Introduction to python

Stack Program in python with source code

 # Stack implementation in python # Creating a stack def create_stack():     stack = []     return stack # Creating an empty stack def check_empty(stack):     return len(stack) == 0 # Adding items into the stack def push(stack, item):     stack.append(item)     print("pushed item: " + item) # Removing an element from the stack def pop(stack):     if (check_empty(stack)):         return "stack is empty"     return stack.pop() stack = create_stack() push(stack, str(1)) push(stack, str(2)) push(stack, str(3)) push(stack, str(4)) print("popped item: " + pop(stack)) print("stack after popping an element: " + str(stack))

Data Structure and Algorithms - Stack LIFO

  A stack is an Abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example – a deck of cards or a pile of plates, etc. A real-world stack allows operations at one end only. For example, we can place or remove a card or plate from the top of the stack only. Likewise, Stack ADT allows all data operations at one end only. At any given time, we can only access the top element of a stack. This feature makes it LIFO data structure. LIFO stands for Last-in-first-out. Here, the element which is placed (inserted or added) last, is accessed first. In stack terminology, insertion operation is called  PUSH  operation and removal operation is called  POP  operation. Basic Operations Stack operations may involve initializing the stack, using it and then de-initializing it. Apart from these basic stuffs, a stack is used for the following two primary operations − push()  − Pushing or adding or accessing an element on th