1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ 4+ < head >
5+ < meta charset ="UTF-8 ">
6+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge ">
7+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
8+ < title > Queue</ title >
9+ </ head >
10+ 11+ < body >
12+ < div align ="center ">
13+ < h3 > Queue with Function</ h3 >
14+ < p > (Open console to check output)</ p >
15+ </ div >
16+ 17+ < script >
18+ let queue = [ ] ;
19+ let currentIndex = queue . length ;
20+ let maxSize = 4 ;
21+ 22+ function enQueue ( newVal ) {
23+ if ( currentIndex >= maxSize ) {
24+ console . error ( "Queue is already full" ) ;
25+ return false ;
26+ }
27+ queue [ currentIndex ] = newVal ;
28+ currentIndex ++ ;
29+ }
30+ 31+ function deQueue ( ) {
32+ if ( currentIndex > 0 ) {
33+ for ( let i = 0 ; i < queue . length ; i ++ ) {
34+ queue [ i ] = queue [ i + 1 ] ;
35+ }
36+ currentIndex -- ;
37+ queue . length -- ;
38+ } else {
39+ console . error ( "Queue is Empty." ) ;
40+ }
41+ }
42+ 43+ function display ( ) {
44+ console . log ( queue ) ;
45+ }
46+ 47+ enQueue ( 5 ) ;
48+ enQueue ( 10 ) ;
49+ enQueue ( 8 ) ;
50+ display ( ) ;
51+ 52+ </ script >
53+ </ body >
54+ 55+ </ html >
0 commit comments