File tree Expand file tree Collapse file tree 2 files changed +26
-14
lines changed Expand file tree Collapse file tree 2 files changed +26
-14
lines changed Original file line number Diff line number Diff line change 11function Stack ( ) {
22
3- this . items = [ ] ;
3+ var items = [ ] ;
44
55 this . push = function ( element ) {
6- this . items . push ( element ) ;
6+ items . push ( element ) ;
77 } ;
88
99 this . pop = function ( ) {
10- return this . items . pop ( ) ;
10+ return items . pop ( ) ;
1111 } ;
1212
1313 this . peek = function ( ) {
14- return this . items [ this . items . length - 1 ] ;
14+ return items [ items . length - 1 ] ;
1515 } ;
1616
1717 this . isEmpty = function ( ) {
18- return this . items . length == 0 ;
18+ return items . length == 0 ;
1919 } ;
2020
2121 this . size = function ( ) {
22- return this . items . length ;
22+ return items . length ;
23+ } ;
24+
25+ this . clear = function ( ) {
26+ items = [ ] ;
2327 } ;
2428
2529 this . print = function ( ) {
26- console . log ( this . items . toString ( ) ) ;
30+ console . log ( items . toString ( ) ) ;
31+ } ;
32+
33+ this . toString = function ( ) {
34+ return items . toString ( ) ;
2735 } ;
2836}
Original file line number Diff line number Diff line change 11function Queue ( ) {
22
3- this . items = [ ] ;
3+ var items = [ ] ;
44
55 this . enqueue = function ( element ) {
6- this . items . push ( element ) ;
6+ items . push ( element ) ;
77 } ;
88
99 this . dequeue = function ( ) {
10- return this . items . shift ( ) ;
10+ return items . shift ( ) ;
1111 } ;
1212
1313 this . front = function ( ) {
14- return this . items [ 0 ] ;
14+ return items [ 0 ] ;
1515 } ;
1616
1717 this . isEmpty = function ( ) {
18- return this . items . length == 0 ;
18+ return items . length == 0 ;
19+ } ;
20+
21+ this . clear = function ( ) {
22+ items = [ ] ;
1923 } ;
2024
2125 this . size = function ( ) {
22- return this . items . length ;
26+ return items . length ;
2327 } ;
2428
2529 this . print = function ( ) {
26- console . log ( this . items . toString ( ) ) ;
30+ console . log ( items . toString ( ) ) ;
2731 } ;
2832}
You can’t perform that action at this time.
0 commit comments