Coder Social home page Coder Social logo

obedrav / lifo-fifo_cmd Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 23 KB

This project provides a command-line interface (CLI) to manage two different data structures: stack and queue.

Python 99.18% Shell 0.82%
lifo-stack python3 queue stack cli cmd doubly-linked-list list

lifo-fifo_cmd's Introduction

Python - Stacks - LIFO, FIFO

Introduction ๐Ÿ˜†

This project provides a command-line interface (CLI) to manage two different data structures: stack and queue. It implements the Last-In, First-Out (LIFO) and First-In, First-Out (FIFO) principles for stack and queue respectively, using two different implementations for each data structure: List and Doubly Linked List. The CLI allows users to interact with the data structures in two modes, interactive and non-interactive, and also accepts files with opcodes as input.

List of Files ๐Ÿฅธ

File Name Description
console.py The CLI that allows you to interact with the data structure
clear The script that deletes the files generated after using the CLI
generate_authors A file with the names and corresponding emails of individual contributors
doubly_linked_list.py The file that manages the Doubly Linked List implementation
list.py The file that manages the List implementation
db_storage.py The file that manages the database storage
file_storage.py The file that manages the file storage

Project Structure ๐Ÿฅด

LIFO-FIFO/
โ”œโ”€โ”€ classes/
โ”‚   โ”œโ”€โ”€ doubly_linked_list.py
โ”‚   โ”œโ”€โ”€ list.py
|   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ engine/
โ”‚       โ”œโ”€โ”€ db_storage.py
โ”‚       โ””โ”€โ”€ file_storage.py
โ”œโ”€โ”€ console.py
โ”œโ”€โ”€ clear
โ”œโ”€โ”€ AUTHORS
โ””โ”€โ”€ generate_authors

Data Structures ๐Ÿง

This project supports two different data structures: Doubly Linked List and List. By default, the program uses List. You can change the data structure used with the environment variable DATA_STRUCTURE when running the CLI.

For example, to use Doubly Linked List as the data structure, you can run:

DATA_STRUCTURE="linkedlist" ./console.py

Storage ๐Ÿค“

This project supports two different storage types: file-storage and database. By default, the program uses file-storage with JSON, which stores all the data in a JSON file called storage.json. You can change the storage used with the environment variable STORAGE when running the CLI.

For example, to use database storage, you can run:

STORAGE="database" ./console.py

When you use database storage, a file called database.db will appear, since this project uses SQLite databases, which is a popular lightweight relational database management system that stores data in a file-based database.

Allowable opcodes and what they do ๐Ÿ‘พ

This project supports the following opcodes:

Opcode Functionality
push Add element to the 'top' of stack and 'end' of queue
pop Remove element from 'top' of stack and 'end' of queue
pall Print every member of the structure
pint Prints the member value at the top of stack
swap Swaps the order of the 1st and 2nd elements in stack

Usage ๐Ÿค–

Files ๐Ÿ’ฌ

Create a file with opcodes, for example:

$ cat someopcodes.txt
push 1
push 2
push 3
add 9
pall

Pass the file to the console using the following command:

$ cat someopcodes.txt | ./console.py
1
9
2
3

And if you want to use a environment variable you can run cat <filename> | <variable_name>="<value>" ./console.py, for example:

$ cat someopcodes.txt | STORAGE="database" ./console.py
1
9
2
3
No-Interactive Mode ๐Ÿ’ฌ

Pass opcodes to the console in non-interactive mode using the following command:

$ echo "push 1" | STORAGE="database" ./console.py

And the console will process in no-interative mode, you can run also:

$ echo "pall" | STORAGE="database" ./console.py
1
9
2
3
1
1
1
1
Interactive Mode ๐Ÿ’ฌ

Run the console with the desired environment variables to enter interactive mode, for example:

$ STORAGE="database" ./console.py
You're using List as a data_structure
(List)>

The prompt shows the data structure being used.

$ DATA_STRUCTURE="linkedlist" STORAGE="database" ./console.py
You're using LinkedList as a data_structure
(LinkedList)> 

Enter the desired command:

$ DATA_STRUCTURE="linkedlist" STORAGE="database" ./console.py
You're using LinkedList as a data_structure
(LinkedList)> push 6
(LinkedList)> push 7
(LinkedList)> push 8
(LinkedList)> push 9
(LinkedList)> add 3
(LinkedList)> pall
6
3
7
8
9
(LinkedList)> 

Error Messages ๐Ÿ’ฅ

The program may display several error messages during its execution. Some of the most common ones are:

  • Invalid data, must be an integer: This error message is displayed when you run a command that expects an integer, but you provide another data type or no data at all. This error message will only appear if you use the push or add opcodes.
  • There are no elements in the data structure: This error message is displayed when you try to use an opcode that requires elements in the data structure, but there are none. For example, if you try to pop an element from an empty data structure.
  • There are not enough elements in the data structure: This error message is displayed when you try to swap elements, but there are not enough elements in the data structure to do so.

Things to keep in mind ๐Ÿ‘๏ธโ€๐Ÿ—จ๏ธ

Both linked list and list use the same storage, so information can be shared between them. For example:

$ DATA_STRUCTURE="linkedlist" STORAGE="database" ./console.py
You're using LinkedList as a data_structure
(LinkedList)> pall
6
3
7
8
9
(LinkedList)> quit
$ STORAGE="database" ./console.py
You're using List as a data_structure
(List)> pall
6
3
7
8
9
(List)> quit

Clear ๐Ÿ‘จโ€๐Ÿซ

After testing and using the CLI, you can run:

./clear

To clear your environment space

Bugs ๐Ÿ’ฃ

If you find any bug, please, let us know.

Styling ๐Ÿ“ƒ

All files have been written in the Pycodestyle.

Authors

  • Obed Rayo github

lifo-fifo_cmd's People

Contributors

obedrav 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.