Write a menu driven program to perform the stack and queue related operations | PHP - IProgramX

Q. Write a menu driven program to perform the following stack and queue related operations:[Hint: use Array_push(), Array_pop(), Array_shift(), Array_unshift() ] 
a) Insert an element in stack 
b) Delete an element from stack 
c) Display the contents of stack 
d) Insert an element in queue 
e) Delete an element from queue 
f) Display the contents of queue



HTML File:

<html>
<body bgcolor=skyblue>
<form action="ass2C1.php" method="post">
Enter choice :
<br><input type="radio" name="ch" value=1> Insert element in stack <br>
<input type="radio" name="ch" value=2> Delete element from stack <br>
<input type="radio" name="ch" value=3> Display content of stack <br>
<input type="radio" name="ch" value=4> Insert element in queue<br>
<input type="radio" name="ch" value=5> Delete element from queue <br>
<input type="radio" name="ch" value=6> Display content of queue <br>
<br>

<input type="submit" value="submit">
<input type="reset" value="reset">
</body>

</html>

PHP Function:
NOTE: PHP function is saved as "ass2C1.php"


<html>
<body bgcolor="gold">
<?
$choice=$_POST['ch'];
{
        $arr=array(1,2,3,4,5,6,7,8,9,10);
        switch($choice)
        {
                case 1:
                        array_push($arr,10);
                        print_r($arr);
                        break;
                case 2:
                        $ele=array_pop($arr);
                        echo "Poped element : $ele";
                        break;
                case 3:
                        print_r($arr);
                        break;
                case 4:
                        array_unshift($arr,"10");
                        print_r($arr);
                        break;
                case 5:
                        $ele=array_shift($arr);
                        echo "Deleted element : $ele";
                        break;
                case 6:
                        print_r($arr);
                        break;
        }
}


Output:





Post a Comment

1 Comments

  1. this program is not showing output (eg poped element 10
    )

    ReplyDelete