Skip to content

Data Structure Operations (data_struct.py)

The Data Structure Operations module in NumLex provides classes and functions for creating and manipulating basic data structures like stacks and queues.

Classes and Functions

Simple Stack (SimpleStack)

This class allows for basic stack operations like adding, removing, updating, and searching for items.

  • add(item): Adds an item to the stack if there is space.

    stack = simp_stk(5)
    stack.add(10)
  • delete(): Removes the top item from the stack.

    stack.delete()
  • update(old_item, new_item): Updates an existing item in the stack with a new value.

    stack.update(10, 20)
  • display(): Returns the current items in the stack.

    items = stack.display()
  • count(): Returns the number of items currently in the stack.

    count = stack.count()
  • search(item): Searches for an item in the stack and returns True if found, otherwise False.

    found = stack.search(20)
  • sort(): Sorts the items in the stack.

    stack.sort()
  • isEmpty(): Checks if the stack is empty.

    empty = stack.isEmpty()
  • isFull(): Checks if the stack is full.

    full = stack.isFull()

Simple Queue (SimpleQueue)

This class provides basic queue operations, including adding, removing, updating, and searching for items.

  • Enqueue(item): Adds an item to the queue if there is space.

    queue = simp_que(5)
    queue.Enqueue(10)
  • Dequeue(): Removes the front item from the queue.

    queue.Dequeue()
  • update(old_item, new_item): Updates an existing item in the queue with a new value.

    queue.update(10, 20)
  • display(): Returns the current items in the queue.

    items = queue.display()
  • count(): Returns the number of items currently in the queue.

    count = queue.count()
  • peak(item): Checks if a particular item is in the queue.

    found = queue.peak(20)
  • sort(): Sorts the items in the queue.

    queue.sort()
  • IsEmpty(): Checks if the queue is empty.

    empty = queue.IsEmpty()
  • IsFull(): Checks if the queue is full.

    full = queue.IsFull()

Circular Queue (CircularQueue)

This class provides circular queue operations, allowing for efficient use of memory by reusing space in the queue.

  • add(item): Adds an item to the circular queue if there is space.

    circ_queue = circ_que(5)
    circ_queue.add(10)
  • delete(): Removes the front item from the circular queue.

    item = circ_queue.delete()
  • update(old_item, new_item): Updates an existing item in the circular queue with a new value.

    circ_queue.update(10, 20)
  • display(): Returns the current items in the circular queue.

    items = circ_queue.display()
  • count(): Returns the number of items currently in the circular queue.

    count = circ_queue.count()
  • search(item): Searches for an item in the circular queue and returns True if found, otherwise False.

    found = circ_queue.search(20)
  • sort(): Sorts the items in the circular queue.

    circ_queue.sort()
  • isEmpty(): Checks if the circular queue is empty.

    empty = circ_queue.isEmpty()
  • isFull(): Checks if the circular queue is full.

    full = circ_queue.isFull()