Friday, 13 April 2018

WT-Slip28

28)Write a menu driven program in PHP to perform the following stack and queue related operations.


i.Insert an element in stack
ii.Delete an element from stack
iii.Display the contents of stack
iv.Insert an element in queue
v.Delete an element from queue
vi. Display the contents of queue

                                                                                                                               

<html>
<body>
<form method="post" action="">
Please check the following options to Perform the operations :
<p><input type="radio" name="operation" value="insert_stack">Insert an element in stack</p>
<p><input type="radio" name="operation" value="remove_stack">Delete an element from stack</p>
<p><input type="radio" name="operation" value="disaply_stack">Display the contents of stack</p>
<p><input type="radio" name="operation" value="insert_queue">Insert an element in queue</p>
<p><input type="radio" name="operation" value="remove_queue">Delete an element from queue</p>
<p><input type="radio" name="operation" value="disaply_queue">Display the contents of queue</p>
<p><input type="text" name="element_vaue" value=""/>
<p><input type="submit" name="submit" value="Submit"></p>
</form>
</body>
</html>
<?php
/*Define array*/
$element_arr = array('a','b','c');
$element_arr_new = array();
$operation = $_POST['operation'];
switch($operation) {
 
case'insert_stack':
echo"Original Array Elements : <PRE>";print_r($element_arr);echo"</PRE>";
array_push($element_arr,$_POST['element_vaue']);
echo"Inserted an element in stack<PRE>";print_r($element_arr);echo"</PRE>";
continue;

case'remove_stack':
echo"Original Array Elements : <PRE>";print_r($element_arr);echo"</PRE>";
array_pop($element_arr);
echo"Deleted an element from stack<PRE>";print_r($element_arr);echo"</PRE>";
break;

case'insert_queue':
echo"Original Array Elements : <PRE>";print_r($element_arr);echo"</PRE>";
array_unshift($element_arr,$_POST['element_vaue']);
echo"Inserted an element in queue<PRE>";print_r($element_arr);echo"</PRE>";
break;

case'remove_queue':
echo"Original Array Elements : <PRE>";print_r($element_arr);echo"</PRE>";
array_shift($element_arr);
echo"Deleted an element from queue<PRE>";print_r($element_arr);echo"</PRE>";
break;
      
case'disaply_stack':
echo"Original Array Elements : <PRE>";print_r($element_arr);echo"</PRE>";
//array_shift($element_arr);
//echo"Deleted an element from queue<PRE>";print_r($element_arr);echo"</PRE>";
break;

case'disaply_queue':
echo"Original Array Elements : <PRE>";print_r($element_arr);echo"</PRE>";
//array_shift($element_arr);
//echo"Deleted an element from queue<PRE>";print_r($element_arr);echo"</PRE>";
break;
    
}
?>