@gobalkrishnan/dsa_collection
Version:
Data Structure and Algorthim used to build application
75 lines (57 loc) • 2.25 kB
JavaScript
import { input, closeInput } from '../console_io.js';
import { LinkedList } from '../data_structure/linked_list/circular_doubly_linked_list.js';
export class CircularSinglyLinkedListMenu {
constructor() {}
static process_print() {
console.log("===== Main Menu =====");
console.log("0. Exit");
console.log("1. Insert Begin");
console.log("2. Insert End");
console.log("3. Delete Begin");
console.log("4. Delete End");
console.log("5. Display JSON");
console.log("6. Display");
}
static async process() {
let start = null;
let num = null;
while (num !== '0') {
this.process_print();
// Wait for user input
num = await input("Enter the Option: ");
switch (num) {
case '0': // Exit
console.log("Exiting the program.");
closeInput(); // Close the readline interface here
break;
case '1': // Insert Begin
{
const data = await input("Enter the Data: ");
start = LinkedList.insert_begin(start, data);
break;
}
case '2': // Insert End
{
const data = await input("Enter the Data: ");
start = LinkedList.insert_end(start, data);
break;
}
case '3': {
start = LinkedList.delete_begin(start);
break;
}
case '4': {
start = LinkedList.delete_end(start);
break;
}
case '5':start = LinkedList.display_as_json(start);break;
case '6': start = LinkedList.display(start);break;
default:
console.log("Invalid option. Please try again.");
break;
}
}
}
}
// Run the process method
CircularSinglyLinkedListMenu.process();