Queues JavaScript Implementation Pseudocode and Algorithm
Implementation Pseudocode and Algorithm of Queues JavaScript .Algorithm for Queue
- Create a Array for Queue.
- Create Insert function for inserting value to queue from the back side.
- This function will take value from the user and will insert to queue.
- Create Delete function for deleting value from Queue from front side.
- Delete function will check if the queue is empty then it will show the message. else it will delete the value from the front side.
- Create Display function to display the values in Queue.
- It will run a for loop to display all values in Queue from starting point to end point.
Figure: Queues JavaScript Implementation Pseudocode and Algorithm
Pseudocode for Queue:
- Three buttons for display, insert & delete.
- Var variable= new array()
- Var start
- Var end
- Function insert()
- Get value from the user and add it to the array to end side
- Function delete()
- If(the end is on initial point or start is greater than the end)
- Print empty Queue
- Function display()
- For(starting from start; run until end; increment)
- Print all queue.
Implementation of Queues in JavaScript
Here, we are sharing the code of Implementation of Queues in JavaScript.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
<html> <head> <title> Queue </title> </head> <body> <h1> T4Tutorials </h1> <p> Type insert button to add value to queue </p> <button type="button" onclick="insert()"> insert </button> <p> Type Delete button to Delete value from queue </p> <button type="button" onclick=" del() "> delete </button> <p> Type Display button to print value in queue </p> <button type="button" onclick="display()"> Display </button> <script> var ary = new Array(); var f=-1; var r=-1; function insert() { var p=prompt (" please enter the number that u want to add "); var x = parseInt (p); if(f==-1) { f=0; } r++; ary[r] = x ; } function display() { if(f==-1) document.write ("Queue is empty"); else{ for(var i=f;i<=r;i++){ document.write (ary[i]+ "<br>");} } } function del() { if(f==-1 || f>r){ document.write ("Queue is empty"); }f++; } </script> </body> </html> |
