Skip to content

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

Notifications You must be signed in to change notification settings

ObedRav/LIFO-FIFO_CMD

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published