Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

Data Structures Implementations in Python

This repository contains Python implementations of fundamental data structures: Node, Stack, Queue, and DoublyLinkedList. They were adapted from exercises in my university labs. Feel free to use them as you wish.

Node

The Node class is the building block for linked data structures. Each node contains:

  • value: The data stored in the node.
  • next: A reference to the next Node in the sequence.
  • prev: A reference to the previous Node (used in doubly linked lists).

Stack

The Stack class implements a last-in, first-out (LIFO) stack with the following operations:

  • is_empty(): Returns whether the stack is empty.
  • push(value): Adds an element to the top of the stack.
  • pop(): Removes and returns the value at the top of the stack.
  • peek(): Returns the value at the top without removing it.
  • size(): Returns the number of elements in the stack.

Queue

The Queue class implements a first-in, first-out (FIFO) queue with the following operations:

  • is_empty(): Returns whether the queue is empty.
  • enqueue(value): Adds an element to the end of the queue.
  • dequeue(): Removes and returns the value at the front of the queue.
  • size(): Returns the number of elements in the queue.

DoublyLinkedList

The DoublyLinkedList class implements a doubly linked list with bidirectional links between nodes and the following operations:

  • is_empty(): Returns whether the list is empty.
  • append(value): Adds an element to the end of the list.
  • insertBefore(node, node_to_insert): Inserts node_to_insert immediately before node.
  • insertAfter(node, node_to_insert): Inserts node_to_insert immediately after node.
  • remove(value): Removes the first node with the given value and returns True if found, otherwise False.
  • remove_node(node_to_remove): Removes the specified Node from the list.
  • __str__(): Returns a string representation of the list values.

These implementations provide basic functionality and can serve as building blocks for more complex algorithms and applications.

About

Simple data structers written in python

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages