🥑
Algorithms
  • The Algorithms Interest Group
  • The C++ Programming Language
    • GCC Compiler
    • Fundamental
    • Integrated Environment
    • STL Containers
  • Fundamental Algorithms and Data Structures
    • Greedy
    • Greedy (2022)
    • Binary Search
    • Recursion
    • Linear Structure
    • Generic Tree
  • Graph Theory
    • Generic Graph
    • Minimum Spanning Tree
    • Depth First Search
    • Breadth First Search
    • Shortest Path
    • Network Flow
    • Bipartite Graph
    • Topological Sort
    • Automaton
  • Dynamic Programming
    • Basic Dynamic Programming
Powered by GitBook
On this page
  • Queue
  • Stack

Was this helpful?

  1. Fundamental Algorithms and Data Structures

Linear Structure

PreviousRecursionNextGeneric Tree

Last updated 3 years ago

Was this helpful?

Queue

A Queue is a linear structure that follows a particular order in which the operations are performed. The order is First In First Out (FIFO). A good example of a queue is any queue of consumers for a resource where the consumer that came first is served first.

Types of Queue in Data structure | Queue Data structure Introduction and Operations
class Queue:
    def __init__(self):
        self.queue = []
    
    def push(self, elm):
        self.queue.append(elm)
    
    def pop(self):
        val = self.queue[0]
        del self.queue[0]
        return val

Stack

Stack is a linear data structure that follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out).

class Stack:
    def __init__(self):
        self.stack = []
    
    def push(self, elm):
        self.stack.append(elm)
    
    def pop(self):
        val = self.stack.pop()
        return val

Code to implement

Stack Data Structure and Implementation in Python, Java and C/C++

**Code to implement **

[src code]
[src code]