Code Monkey home page Code Monkey logo

monty's Introduction

LIFO and FIFO:

  • LIFO: Stands for Last In, First Out. The last element added to a collection is the first one to be removed. Think of it like a stack of plates โ€” you remove the top one first.
  • FIFO: Stands for First In, First Out. The first element added is the first one to be removed. It's like a queue of people waiting in line โ€” the person who arrives first is the first to leave.

Stack:

  • Definition: A stack is a data structure that follows the LIFO principle. Elements are added to and removed from the top of the stack.
  • Use cases: Use a stack when you need to keep track of function calls (call stack in recursion), undo mechanisms, or in parsing expressions (like in a calculator).
  • Common implementations: Arrays and linked lists are common implementations of stacks.

Queue:

  • Definition: A queue is a data structure that follows the FIFO principle. Elements are added at the rear (enqueue) and removed from the front (dequeue) of the queue.
  • Use cases: Use a queue when you want to maintain the order of elements and process them in a first-come, first-served manner. Examples include task scheduling, print queue management, or breadth-first search algorithms.
  • Common implementations: Similar to stacks, arrays and linked lists are commonly used to implement queues. There are also specialized implementations like priority queues.

Common Use Cases:

  • Stacks: Function calls (call stack), undo mechanisms, expression parsing, backtracking algorithms.
  • Queues: Task scheduling, print job management, breadth-first search, handling requests in a web server.

Global Variables:

  • Proper Usage: Using global variables should be minimized due to the potential for unintended side effects and difficulties in debugging and maintaining code. If you must use global variables, consider the following:
    • Clearly document the variables and their purpose.
    • Avoid using global variables for mutable state if possible.
    • Use all capital letters for global constants to distinguish them from regular variables.
    • Be cautious of unintended interactions with other parts of the code.

Remember, excessive use of global variables can make code less modular and harder to understand. It's often better to pass necessary variables explicitly through function parameters or encapsulate them in appropriate data structures.

monty's People

Contributors

mutai05 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.