Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Change the program so that implements a stack of strings instead of a stack of n

ID: 3621137 • Letter: C

Question

Change the program so that implements a stack of strings instead of a stack of numbers

// Variables

var STACK = new Array(100) ; // numeric

var TOP; // numeric

// Functions

Function push(item /*numeric*/) // void

{

            if ((TOP < 100))

            {

                  TOP = TOP + 1;

                   STACK[TOP] = item;

            }

}

function pop () // numeric

{

            var item; // numeric

            if ((TOP >= 0))

            {

                        item =STACK[TOP];

                        TOP = TOP – 1;

                        return item;

            }

            else

            {

                        return 0;

            }

}

// Main Program

TOP = -1;

push(10)

push(20)

push(30)

document.writeln(pop());

document.writeln(pop());

document.writeln(pop());

Explanation / Answer

Dear.. var STACK = new Array(100) ; // numeric var TOP; // numeric function push(item) { if ((TOP < 100)) { TOP = TOP + 1; STACK[TOP] = item; return item; } } function pop () { var item; if ((TOP >= 0)) { item =STACK[TOP]; TOP = TOP - 1; return item; } else { return 0; } } // Main Program TOP = -1; document.write("strings that are pushed :
") document.writeln(push("one")) document.writeln(push("two")) document.writeln(push("three")) document.write("
") document.write("Popping Out :
") document.writeln(pop()); document.writeln(pop()); document.writeln(pop()); out put: strings that are pushed : one two three Popping Out : three two one
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote