<div class=”entry-content”><div id=”toc_container” class=”no_bullets contracted” style=”width: auto; display: table;”><p class=”toc_title”>Contents <span class=”toc_toggle”>[<a href=”#”>show</a>]</span></p><ul class=”toc_list” style=”display: none;”><li><a href=”#NCERT_Solutions_for_Class_12_Computer_Science_C_8211_Stack”><span class=”toc_number toc_depth_1″>1</span> NCERT Solutions for Class 12 Computer Science (C++) – Stack</a><ul><li><a href=”#Short_Answer_Type_Questions-I2_marks_each”><span class=”toc_number toc_depth_2″>1.1</span> Short Answer Type Questions-I[2 marks each]</a></li><li><a href=”#Short_Answer_Type_Questions-II3_marks_each”><span class=”toc_number toc_depth_2″>1.2</span> Short Answer Type Questions-II[3 marks each]</a></li><li><a href=”#Long_Answer_Type_Questions4_marks_each”><span class=”toc_number toc_depth_2″>1.3</span> Long Answer Type Questions[4 marks each]</a></li></ul></li></ul></div>
<h2><span id=”NCERT_Solutions_for_Class_12_Computer_Science_C_8211_Stack”><span style=”color: #00ccff;”><strong>NCERT Solutions for Class 12 Computer Science (C++) – Stack</strong></span></span></h2>
<h3 style=”text-align: center;”><span id=”Short_Answer_Type_Questions-I2_marks_each”><span style=”color: #0000ff;”>Short Answer Type Questions-I[2 marks each]</span></span></h3>
<p><strong><span style=”color: #eb4924;”>Question 1.</span></strong><br>
Evaluate the following postfix expression. Show the status of stack after execution of each operation separately:<br>
2,13, + , 5, -,6,3,/,5,*,<<br>
<strong><span style=”color: #008000;”>Answer:</span></strong></p><div class=”code-block code-block-1″ style=”margin: 8px 0; clear: both;”>
<script async=”” src=”//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js” type=”text/javascript”></script>
<ins class=”adsbygoogle adsbygoogle-ablated-ad-slot adsbygoogle-noablate” style=”display: block;” data-ad-client=”ca-pub-7398766921532682″ data-ad-slot=”8094000682″ data-ad-format=”auto” data-adsbygoogle-status=”done” google_element_uid=”1″ data-ad-status=”filled”><div id=”aswift_1_host” tabindex=”0″ title=”Advertisement” aria-label=”Advertisement” style=”border: none; height: 280px; width: 750px; margin: 0px; padding: 0px; position: relative; visibility: visible; background-color: transparent; display: inline-block;”><iframe id=”aswift_1″ name=”aswift_1″ style=”left:0;position:absolute;top:0;border:0;width:750px;height:280px;” sandbox=”allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-top-navigation-by-user-activation” width=”750″ height=”280″ frameborder=”0″ marginwidth=”0″ marginheight=”0″ vspace=”0″ hspace=”0″ allowtransparency=”true” scrolling=”no” src=”https://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-7398766921532682&output=html&h=280&slotname=8094000682&adk=2916952469&adf=1164200656&pi=t.ma~as.8094000682&w=750&lmt=1671635575&format=750×280&url=https%3A%2F%2Fwww.cbsetuts.com%2Fncert-solutions-class-12-computer-science-c-stack%2F&wgl=1&adsid=ChEIgPvEnQYQ7oKUkIGo7bvHARI9AMmKl4kPKHcQrvOQS38Zsa4NDRHJ640u-ohwa96qkzOSN8n-ZNQ_kbXCMGPRxqNOjEPrMPaAXCWHJV21Eg&uach=WyJXaW5kb3dzIiwiMTAuMC4wIiwieDg2IiwiIiwiMTA4LjAuNTM1OS4xMjUiLFtdLGZhbHNlLG51bGwsIjY0IixbWyJOb3Q_QV9CcmFuZCIsIjguMC4wLjAiXSxbIkNocm9taXVtIiwiMTA4LjAuNTM1OS4xMjUiXSxbIkdvb2dsZSBDaHJvbWUiLCIxMDguMC41MzU5LjEyNSJdXSxmYWxzZV0.&dt=1672585017433&bpp=2&bdt=2872&idt=-M&shv=r20221207&mjsv=m202212050101&ptt=9&saldr=aa&abxe=1&cookie=ID%3D70877dca39d7cee1-22c4db3411d900f8%3AT%3D1672348851%3ART%3D1672348851%3AS%3DALNI_MYJDyG_bu32YHEUMIGJIo2bVt3_WQ&gpic=UID%3D00000b9a5c88ec58%3AT%3D1672348851%3ART%3D1672575613%3AS%3DALNI_Mb87E1-6Z_pG79EP2w2fRKpjdy0KA&prev_fmts=0x0&nras=1&correlator=8090153285664&frm=20&pv=1&ga_vid=540223204.1672348852&ga_sid=1672585016&ga_hid=1785046434&ga_fc=1&u_tz=330&u_his=12&u_h=768&u_w=1366&u_ah=728&u_aw=1366&u_cd=24&u_sd=1&dmc=4&adx=105&ady=683&biw=1349&bih=657&scr_x=0&scr_y=0&eid=44759875%2C44759926%2C44759837%2C44777506%2C31071168%2C44774606%2C44780792&oid=2&pvsid=3302314963386371&tmod=1209859931&uas=3&nvt=1&ref=https%3A%2F%2Fwww.learncbse.in%2F&eae=0&fc=1920&brdim=0%2C0%2C0%2C0%2C1366%2C0%2C1366%2C728%2C1366%2C657&vis=1&rsz=%7C%7CeEbr%7C&abl=CS&pfx=0&fu=0&bc=31&jar=2022-12-31-10&ifi=2&uci=a!2&btvi=1&fsb=1&xpc=hMBWIucQQJ&p=https%3A//www.cbsetuts.com&dtd=34″ data-google-container-id=”a!2″ data-google-query-id=”CJLdvd7QpvwCFTaH6QUdR28Bmg” data-load-complete=”true”></iframe></div></ins><div class=”google-auto-placed adsbygoogle-resurrected-ad-slot” style=”width: 100%; height: auto; clear: none; text-align: center;”><ins data-ad-format=”750×280″ class=”adsbygoogle adsbygoogle-noablate” data-ad-client=”ca-pub-7398766921532682″ data-ad-slot=”8094000682″ data-adsbygoogle-status=”done” style=”display: block; margin: auto; background-color: transparent;” data-ad-status=”filled”><div id=”aswift_4_host” tabindex=”0″ title=”Advertisement” aria-label=”Advertisement” style=”border: none; height: 280px; width: 750px; margin: 0px; padding: 0px; position: relative; visibility: visible; background-color: transparent; display: inline-block;”><iframe id=”aswift_4″ name=”aswift_4″ style=”left:0;position:absolute;top:0;border:0;width:750px;height:280px;” sandbox=”allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-top-navigation-by-user-activation” width=”750″ height=”280″ frameborder=”0″ marginwidth=”0″ marginheight=”0″ vspace=”0″ hspace=”0″ allowtransparency=”true” scrolling=”no” src=”https://googleads.g.doubleclick.net/pagead/ads?client=ca-pub-7398766921532682&output=html&h=280&slotname=8094000682&adk=131497406&adf=2443109733&pi=t.ma~as.8094000682&w=750&lmt=1671635575&format=750×280&url=https%3A%2F%2Fwww.cbsetuts.com%2Fncert-solutions-class-12-computer-science-c-stack%2F&wgl=1&adsid=ChEIgPvEnQYQ7oKUkIGo7bvHARI9AMmKl4kPKHcQrvOQS38Zsa4NDRHJ640u-ohwa96qkzOSN8n-ZNQ_kbXCMGPRxqNOjEPrMPaAXCWHJV21Eg&uach=WyJXaW5kb3dzIiwiMTAuMC4wIiwieDg2IiwiIiwiMTA4LjAuNTM1OS4xMjUiLFtdLGZhbHNlLG51bGwsIjY0IixbWyJOb3Q_QV9CcmFuZCIsIjguMC4wLjAiXSxbIkNocm9taXVtIiwiMTA4LjAuNTM1OS4xMjUiXSxbIkdvb2dsZSBDaHJvbWUiLCIxMDguMC41MzU5LjEyNSJdXSxmYWxzZV0.&dt=1672585017573&bpp=2&bdt=3012&idt=-M&shv=r20221207&mjsv=m202212050101&ptt=9&saldr=aa&abxe=1&cookie=ID%3D70877dca39d7cee1-22c4db3411d900f8%3AT%3D1672348851%3ART%3D1672348851%3AS%3DALNI_MYJDyG_bu32YHEUMIGJIo2bVt3_WQ&gpic=UID%3D00000b9a5c88ec58%3AT%3D1672348851%3ART%3D1672575613%3AS%3DALNI_Mb87E1-6Z_pG79EP2w2fRKpjdy0KA&prev_fmts=0x0%2C750x280%2C300x600&nras=1&correlator=8090153285664&frm=20&pv=1&ga_vid=540223204.1672348852&ga_sid=1672585016&ga_hid=1785046434&ga_fc=1&u_tz=330&u_his=12&u_h=768&u_w=1366&u_ah=728&u_aw=1366&u_cd=24&u_sd=1&dmc=4&adx=105&ady=971&biw=1349&bih=657&scr_x=0&scr_y=0&eid=44759875%2C44759926%2C44759837%2C44777506%2C31071168%2C44774606%2C44780792&oid=2&pvsid=3302314963386371&tmod=1209859931&uas=3&nvt=1&ref=https%3A%2F%2Fwww.learncbse.in%2F&eae=0&fc=1920&brdim=0%2C0%2C0%2C0%2C1366%2C0%2C1366%2C728%2C1366%2C657&vis=1&rsz=%7C%7CeEbr%7C&abl=CS&pfx=0&fu=0&bc=31&jar=2022-12-31-10&ifi=5&uci=a!5&btvi=3&fsb=1&xpc=lTjLTFnfJk&p=https%3A//www.cbsetuts.com&dtd=60″ data-google-container-id=”a!5″ data-google-query-id=”CJ3ayN7QpvwCFXuI6QUdSgMM0w” data-load-complete=”true”></iframe></div></ins></div>
<script type=”text/javascript”>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></div>
<table style=”height: 1009px;” border=”2″ width=”350″>
<tbody>
<tr>
<td width=”96″>
<p style=”text-align: center;”>ITEM<br>
SCANNED</p>
</td>
<td style=”text-align: center;” width=”198″>OPERATION</td>
<td style=”text-align: center;” width=”114″>STACK</td>
</tr>
<tr>
<td style=”text-align: center;” width=”96″>2</td>
<td style=”text-align: center;” width=”198″>PUSH 2</td>
<td style=”text-align: center;” width=”114″>2</td>
</tr>
<tr>
<td style=”text-align: center;” width=”96″>13</td>
<td style=”text-align: center;” width=”198″>PUSH 13</td>
<td style=”text-align: center;” width=”114″>2,13</td>
</tr>
<tr>
<td style=”text-align: center;” width=”96″>+</td>
<td style=”text-align: center;” width=”198″>POP 13 and 2<br>
Evaluate 2 + 13 = 15<br>
PUSH 15</td>
<td style=”text-align: center;” width=”114″>15</td>
</tr>
<tr>
<td style=”text-align: center;” width=”96″>5</td>
<td style=”text-align: center;” width=”198″>PUSH 5</td>
<td style=”text-align: center;” width=”114″>15,5</td>
</tr>
<tr>
<td style=”text-align: center;” width=”96″>–</td>
<td style=”text-align: center;” width=”198″>POP 5 & 15<br>
EVALUATE 15-5 = 10<br>
PUSH 10</td>
<td style=”text-align: center;” width=”114″>10</td>
</tr>
<tr>
<td style=”text-align: center;” width=”96″>6</td>
<td style=”text-align: center;” width=”198″>PUSH 6</td>
<td style=”text-align: center;” width=”114″>10, 6</td>
</tr>
<tr>
<td style=”text-align: center;” width=”96″>3</td>
<td style=”text-align: center;” width=”198″>PUSH 3</td>
<td style=”text-align: center;” width=”114″>10, 6, 3</td>
</tr>
<tr>
<td style=”text-align: center;” width=”96″>/</td>
<td style=”text-align: center;” width=”198″>POP 3 & 6<br>
EVALUATE 6/3= 2<br>
PUSH 2</td>
<td style=”text-align: center;” width=”114″>10,2</td>
</tr>
<tr>
<td style=”text-align: center;” width=”96″>5</td>
<td style=”text-align: center;” width=”198″>PUSH 5</td>
<td style=”text-align: center;” width=”114″>10, 2, 5</td>
</tr>
<tr>
<td style=”text-align: center;” width=”96″>*</td>
<td style=”text-align: center;” width=”198″>POP 5 & 2<br>
EVALUATE 2*5 = 10<br>
PUSH 10</td>
<td style=”text-align: center;” width=”114″>10, 10</td>
</tr>
<tr>
<td style=”text-align: center;” width=”96″><</td>
<td style=”text-align: center;” width=”198″>POP 10 & 10<br>
EVALUATE<br>
10<10 = FALSE<br>
PUSH FALSE</td>
<td style=”text-align: center;” width=”114″>FALSE</td>
</tr>
</tbody>
</table>
<p class=”MSGENFONTSTYLENAMETEMPLATEROLEMSGENFONTSTYLENAMEBYROLETABLECAPTION0″ style=”background: transparent;”><span class=”MSGENFONTSTYLENAMETEMPLATEROLEMSGENFONTSTYLENAMEBYROLETABLECAPTIONExact”>RESULT = FALSE</span></p>
<p><strong><span style=”color: #eb4924;”>Question 2.</span></strong><br>
Evaluate the following postfix expression : (show status of Stack after each operation)<br>
100,40,8,/,20,10,-,+,*<br>
<strong><span style=”color: #008000;”>Answer:</span></strong></p>
<table style=”height: 714px;” border=”2″ width=”387″>
<tbody>
<tr>
<td width=”77″>
<p style=”text-align: center;”>ITEM</p>
<p style=”text-align: center;”>SCANNED</p>
</td>
<td style=”text-align: center;” width=”145″>OPERATION</td>
<td style=”text-align: center;” width=”78″>STACK</td>
</tr>
<tr>
<td width=”77″>100</td>
<td width=”145″>PUSH 100</td>
<td width=”78″>100</td>
</tr>
<tr>
<td width=”77″>40</td>
<td width=”145″>PUSH 40</td>
<td width=”78″>100,40</td>
</tr>
<tr>
<td width=”77″>8</td>
<td width=”145″>PUSH 8</td>
<td width=”78″>100,40,8</td>
</tr>
<tr>
<td width=”77″>/</td>
<td width=”145″>POP 8<br>
POP 40<br>
EVALUATE 40/8 =5<br>
PUSH 5</td>
<td width=”78″>100,5</td>
</tr>
<tr>
<td width=”77″>20</td>
<td width=”145″>PUSH 20</td>
<td width=”78″>100,5,20</td>
</tr>
<tr>
<td width=”77″>10</td>
<td width=”145″>PUSH 10</td>
<td width=”78″>100, 5, 20, 10</td>
</tr>
<tr>
<td width=”77″></td>
<td width=”145″>POP 10<br>
POP 20<br>
EVALUATE 20-10 =10<br>
PUSH 10</td>
<td width=”78″>100,5,10</td>
</tr>
<tr>
<td width=”77″>+</td>
<td width=”145″>POP 10 POP 5<br>
EVALUATE 10 + 5= 15 PUSH 15</td>
<td width=”78″>100,15</td>
</tr>
<tr>
<td width=”77″>*</td>
<td width=”145″>POP 15<br>
POP 100<br>
EVALUATE 100 * 15 = 1500<br>
PUSH 1500</td>
<td width=”78″>1500</td>
</tr>
</tbody>
</table>
<p><strong><span style=”color: #eb4924;”>Question 3.</span></strong><br>
Evaluate the following postfix expression. Show the status of stack after execution of each operation separately:<br>
T, F, NOT, AND, T, OR, F, AND<br>
<strong><span style=”color: #008000;”>Answer:</span></strong></p>
<table border=”2″>
<tbody>
<tr>
<td width=”50″>S.No.</td>
<td width=”85″>Scanned Element</td>
<td width=”84″>Operation</td>
<td width=”85″>Stack</td>
</tr>
<tr>
<td width=”50″>1</td>
<td width=”85″>True</td>
<td width=”84″>PUSH True</td>
<td width=”85″>True</td>
</tr>
<tr>
<td width=”50″>2</td>
<td width=”85″>False</td>
<td width=”84″>PUSH False</td>
<td width=”85″>False</td>
</tr>
<tr>
<td width=”50″>3<p></p>
<p> </p></td>
<td width=”85″>NOT<p></p>
<p>Calculate NOT False</p></td>
<td width=”84″>POP False<p></p>
<p>PUSH True</p></td>
<td width=”85″>True<p></p>
<p>True, True</p></td>
</tr>
<tr>
<td width=”50″>4<p></p>
<p> </p></td>
<td width=”85″>And<p></p>
<p>calculate:</p>
<p>True AND True</p></td>
<td width=”84″>POP True POP True<p></p>
<p>PUSH True</p></td>
<td width=”85″>True<p></p>
<p>True</p></td>
</tr>
<tr>
<td width=”50″>5</td>
<td width=”85″>True</td>
<td width=”84″>PUSH True</td>
<td width=”85″>True, True</td>
</tr>
<tr>
<td width=”50″>6<p></p>
<p> </p></td>
<td width=”85″>OR<p></p>
<p>Calculate: True OR True</p></td>
<td width=”84″>POP True<p></p>
<p>PUSH True</p></td>
<td width=”85″>True<p></p>
<p>True</p></td>
</tr>
<tr>
<td width=”50″>7</td>
<td width=”85″>False</td>
<td width=”84″>PUSH False</td>
<td width=”85″>True, False</td>
</tr>
<tr>
<td width=”50″>8<p></p>
<p> </p></td>
<td width=”85″>AND<p></p>
<p>Calculate: True AND False</p></td>
<td width=”84″>POP False<p></p>
<p>POP True PUSH False</p></td>
<td width=”85″>True<p></p>
<p>False</p></td>
</tr>
</tbody>
</table>
<p>Thus the stack will have False Value</p>
<p><strong><span style=”color: #eb4924;”>Question 4.</span></strong><br>
Evaluate the following postfix expression. Show the status of stack after execution of each operation separately:<br>
F, T, NOT, AND, F, OR, T, AND<br>
<strong><span style=”color: #008000;”>Answer:</span></strong></p>
<table style=”height: 896px;” border=”2″ width=”375″>
<tbody>
<tr>
<td style=”text-align: center;” width=”52″>S.No.</td>
<td style=”text-align: center;” width=”113″>Scanned Element</td>
<td style=”text-align: center;” width=”80″>Operation</td>
<td style=”text-align: center;” width=”77″>Stack</td>
</tr>
<tr>
<td style=”text-align: center;” width=”52″>1</td>
<td width=”113″>F</td>
<td width=”80″>PUSH F</td>
<td width=”77″>F</td>
</tr>
<tr>
<td style=”text-align: center;” width=”52″>2</td>
<td width=”113″>T</td>
<td width=”80″>PUSH T</td>
<td width=”77″>F,T</td>
</tr>
<tr>
<td style=”text-align: center;” width=”52″>3</td>
<td width=”113″>NOT<p></p>
<p>Calculate NOT T</p></td>
<td width=”80″>POP T<p></p>
<p>PUSH F</p></td>
<td width=”77″>F<p></p>
<p>F,F</p></td>
</tr>
<tr>
<td style=”text-align: center;” width=”52″>4</td>
<td width=”113″>AND<p></p>
<p>Calculate NOT</p></td>
<td width=”80″>POP F<p></p>
<p>POP F</p>
<p>PUSH F</p></td>
<td width=”77″>F<p></p>
<p>F</p></td>
</tr>
<tr>
<td style=”text-align: center;” width=”52″>5</td>
<td width=”113″>F</td>
<td width=”80″>PUSH F</td>
<td width=”77″>F,F</td>
</tr>
<tr>
<td style=”text-align: center;” width=”52″>6</td>
<td width=”113″>OR</td>
<td width=”80″>POP F<p></p>
<p>POP F</p>
<p> </p></td>
<td width=”77″></td>
</tr>
<tr>
<td style=”text-align: center;” width=”52″>7</td>
<td width=”113″>T</td>
<td width=”80″>PUSH T</td>
<td width=”77″>F,T</td>
</tr>
<tr>
<td style=”text-align: center;” width=”52″>8</td>
<td width=”113″>AND</td>
<td width=”80″>POP T<p></p>
<p>POP F</p>
<p>PUSH F</p></td>
<td width=”77″>F<p></p>
<p>F</p></td>
</tr>
</tbody>
</table>
<p>Thus the stack will have False Value</p>
<p><strong><span style=”color: #eb4924;”>Question 5.</span></strong><br>
Evaluate the following postfix expression using a stack and show the contents of stack after execution of each operation:<br>
5,3,2, *, 4,2, /, -,*<br>
<strong><span style=”color: #008000;”>Answer:</span></strong></p>
<table border=”2″>
<tbody>
<tr>
<td style=”text-align: center;” width=”108″>SYMBOL</td>
<td style=”text-align: center;” width=”113″>STACK</td>
<td style=”text-align: center;” width=”103″>OUTPUT</td>
</tr>
<tr>
<td style=”text-align: center;” width=”108″>5</td>
<td width=”113″></td>
<td width=”103″>5</td>
</tr>
<tr>
<td style=”text-align: center;” width=”108″>3</td>
<td width=”113″></td>
<td width=”103″>5,3</td>
</tr>
<tr>
<td style=”text-align: center;” width=”108″>2</td>
<td width=”113″></td>
<td width=”103″>5,3,2</td>
</tr>
<tr>
<td style=”text-align: center;” width=”108″>*</td>
<td width=”113″>PUSH 3,2<p></p>
<p>Perform 3*2=6</p>
<p>POP 6</p></td>
<td width=”103″>5<p></p>
<p>5</p>
<p>5,6</p></td>
</tr>
<tr>
<td style=”text-align: center;” width=”108″>4</td>
<td width=”113″></td>
<td width=”103″>5,6,4</td>
</tr>
<tr>
<td style=”text-align: center;” width=”108″>2</td>
<td width=”113″></td>
<td width=”103″>5,6,4,2</td>
</tr>
<tr>
<td style=”text-align: center;” width=”108″>/</td>
<td width=”113″>PUSH 4,2<p></p>
<p>Perform 4/2=2</p>
<p>POP2</p></td>
<td width=”103″>5,6<p></p>
<p>5,6</p>
<p>5,6,2</p></td>
</tr>
<tr>
<td style=”text-align: center;” width=”108″>–</td>
<td width=”113″>PUSH 6,2<p></p>
<p>Perform 6-2=4</p>
<p>POP 4</p></td>
<td width=”103″>5<p></p>
<p>5</p>
<p>5,4</p></td>
</tr>
<tr>
<td style=”text-align: center;” width=”108″>*</td>
<td width=”113″>PUSH 5,4<p></p>
<p>perform 5*4=20.</p>
<p>POP 20</p></td>
<td width=”103″>20</td>
</tr>
</tbody>
</table>
<p>Result=20</p>
<p><strong><span style=”color: #eb4924;”>Question 6.</span></strong><br>
Evaluate the following POSTFIX notation. Show status of Stack after every step of evaluation (i.e. after each operation)<br>
False NOT, True, AND, True, False, OR, AND<br>
<strong><span style=”color: #008000;”>Answer:</span></strong></p>
<table border=”2″>
<tbody>
<tr>
<td style=”text-align: center;” width=”150″>Element Scanned</td>
<td style=”text-align: center;” width=”151″>Stack Status</td>
</tr>
<tr>
<td width=”150″>False</td>
<td width=”151″>False</td>
</tr>
<tr>
<td width=”150″>NOT</td>
<td width=”151″>True</td>
</tr>
<tr>
<td width=”150″>True</td>
<td width=”151″>True, True</td>
</tr>
<tr>
<td width=”150″>AND</td>
<td width=”151″>True</td>
</tr>
<tr>
<td width=”150″>True</td>
<td width=”151″>True, True</td>
</tr>
<tr>
<td width=”150″>False</td>
<td width=”151″>True, True, False</td>
</tr>
<tr>
<td width=”150″>OR</td>
<td width=”151″>True, True</td>
</tr>
<tr>
<td width=”150″>AND</td>
<td width=”151″>True</td>
</tr>
</tbody>
</table>
<p>Final Answer: True</p>
<p><strong><span style=”color: #eb4924;”>Question 7.</span></strong><br>
Top is a pointer variable pointing to the top element of a stack, with each node having the following structure declaration:<br>
<strong>struct Stack {int Data, Stack * Next}; </strong><br>
Considering the above explanation, what will the following code do ?<br>
int count = 0, Sum = 0;</p>
<pre>Stack * Temp = Top;
while (Temp – > Next! = NULL)
{ count + +;
Sum + = Temp – > Data;
Temp Temp – > Next;
}
count < < Sum / count;</pre>
<p><strong><span style=”color: #008000;”>Answer:</span></strong><br>
It will calculate the average of stack values.</p>
<p><strong><span style=”color: #eb4924;”>Question 8.</span></strong><br>
Convert the expression ((x * 3 + y * 3 + z * 3) / (x + y + z)) into postfix expression. Show the content of the stack during the conversion.<br>
<strong><span style=”color: #008000;”>Answer:</span></strong><br>
Given expression : ((x * 3 + y * 3 + z * 3) / (x + y + z))<br>
((x * 3 + y * 3 + z * 3) / (x + y + z))</p>
<table style=”height: 1036px;” border=”2″ width=”414″>
<tbody>
<tr>
<td width=”110″>
<p style=”text-align: center;”>Symbol</p>
<p style=”text-align: center;”>Scanned</p>
</td>
<td style=”text-align: center;” width=”123″>Stack</td>
<td style=”text-align: center;” width=”252″>Expression</td>
</tr>
<tr>
<td width=”110″>(<p></p>
<p>(</p>
<p>X</p>
<p>*</p></td>
<td width=”123″>(<p></p>
<p>((</p>
<p>((</p>
<p>((*</p></td>
<td width=”252″>—<p></p>
<p>—</p>
<p>X</p>
<p>X</p></td>
</tr>
<tr>
<td width=”110″>3<p></p>
<p>+</p>
<p>y</p>
<p>X-</p>
<p>3</p>
<p>+</p>
<p>z</p>
<p>X-</p>
<p>3</p>
<p>)</p>
<p>/</p>
<p>(</p>
<p>X</p>
<p>+</p>
<p>y</p>
<p>+</p>
<p>Z</p>
<p>)</p>
<p>)</p></td>
<td width=”123″>((*<p></p>
<p>((* +</p>
<p>((* +</p>
<p>((* + *</p>
<p>((* + *</p>
<p>((* + * +</p>
<p>((* + * +</p>
<p>((* + * + *</p>
<p>((* + * + *</p>
<p>(</p>
<p>(/</p>
<p>(/(</p>
<p>(/(</p>
<p>(/(+</p>
<p>(/(+</p>
<p></(+ +</p>
<p>(/(+ +</p>
<p>(/</p></td>
<td width=”252″>x3<p></p>
<p>x3</p>
<p>x3y</p>
<p>x3y</p>
<p>x3y3</p>
<p>x3y3</p>
<p>x3y3z</p>
<p>x3y3z</p>
<p>x3y3z3</p>
<p>x3y3z3 * + * + *</p>
<p>x3y3z3 * + * + *</p>
<p>x3y3z3* + * + *</p>
<p>x3y3z3 * + * + * x</p>
<p>x3y3z3 * + * + * x •</p>
<p>x3y3z3 * + * + * x y</p>
<p>x3y3z3 * + * + * x y</p>
<p>x3y3z3 * + * + * xyz</p>
<p>x3y3z3 * + * + * xyz + +</p>
<p>x3y3z3 * + * + * xyz + +/</p></td>
</tr>
</tbody>
</table>
<p class=”MSGENFONTSTYLENAMETEMPLATEROLEMSGENFONTSTYLENAMEBYROLETABLECAPTION0″ style=”background: transparent; text-align: left;” align=”center”>\Postfix expression is: x3y3z3 * + * + * xyz + +/</p>
<p><strong><span style=”color: #eb4924;”>Question 9.</span></strong><br>
Evaluate the following POSTFIX expression, show the status of Stack after execution of each operation separaterly:<br>
45,45,+,32,20,10,/,-,*<br>
<strong><span style=”color: #008000;”>Answer:</span></strong></p>
<table border=”2″>
<tbody>
<tr>
<td style=”text-align: center;” width=”130″>Element Scanned</td>
<td style=”text-align: center;” width=”125″>Stack Status</td>
</tr>
<tr>
<td width=”130″>45</td>
<td width=”125″>45</td>
</tr>
<tr>
<td width=”130″> 45</td>
<td width=”125″> 45,45</td>
</tr>
<tr>
<td width=”130″>+</td>
<td width=”125″> 90</td>
</tr>
<tr>
<td width=”130″> 32</td>
<td width=”125″>90,32</td>
</tr>
<tr>
<td width=”130″>20</td>
<td width=”125″>90,32,20</td>
</tr>
<tr>
<td width=”130″> 10</td>
<td width=”125″>90,32,20,10</td>
</tr>
<tr>
<td width=”130″>/</td>
<td width=”125″>90,32,2</td>
</tr>
<tr>
<td width=”130″>–</td>
<td width=”125″>90,30</td>
</tr>
<tr>
<td width=”130″>*</td>
<td width=”125″>2700</td>
</tr>
</tbody>
</table>
<p>Hence the final result is 2700</p>
<p><strong><span style=”color: #eb4924;”>Question 10.</span></strong><br>
Convert the following Infix expression to its equivalent Postfix expression, showing the stack contents for each step of conversion.<br>
P/Q+(R-T)*U<br>
<strong><span style=”color: #008000;”>Answer:</span></strong><br>
P/Q+(R-T)*U = (P/Q+(R-T)*U)</p>
<table style=”height: 500px;” border=”2″ width=”312″>
<tbody>
<tr>
<td style=”text-align: center;” width=”79″>Element</td>
<td style=”text-align: center;” width=”87″>Stack of Operator</td>
<td width=”95″>
<p style=”text-align: center;”>Postfix</p>
<p style=”text-align: center;”>Expression</p>
</td>
</tr>
<tr>
<td style=”text-align: center;” width=”79″>(</td>
<td style=”text-align: center;” width=”87″>(</td>
<td style=”text-align: center;” width=”95″></td>
</tr>
<tr>
<td style=”text-align: center;” width=”79″>P</td>
<td style=”text-align: center;” width=”87″>(</td>
<td style=”text-align: center;” width=”95″>P</td>
</tr>
<tr>
<td style=”text-align: center;” width=”79″>/</td>
<td style=”text-align: center;” width=”87″>(/</td>
<td style=”text-align: center;” width=”95″>P</td>
</tr>
<tr>
<td style=”text-align: center;” width=”79″>Q</td>
<td style=”text-align: center;” width=”87″></</td>
<td style=”text-align: center;” width=”95″>PQ</td>
</tr>
<tr>
<td style=”text-align: center;” width=”79″>+</td>
<td style=”text-align: center;” width=”87″>(/+</td>
<td style=”text-align: center;” width=”95″>PQ</td>
</tr>
<tr>
<td style=”text-align: center;” width=”79″>(</td>
<td style=”text-align: center;” width=”87″>(/+(</td>
<td style=”text-align: center;” width=”95″>PQ</td>
</tr>
<tr>
<td style=”text-align: center;” width=”79″>R</td>
<td style=”text-align: center;” width=”87″>(/+(</td>
<td style=”text-align: center;” width=”95″>PQR</td>
</tr>
<tr>
<td style=”text-align: center;” width=”79″>–</td>
<td style=”text-align: center;” width=”87″>(/+(-</td>
<td style=”text-align: center;” width=”95″>PQR</td>
</tr>
<tr>
<td style=”text-align: center;” width=”79″>T</td>
<td style=”text-align: center;” width=”87″>(/+c-</td>
<td style=”text-align: center;” width=”95″>PQRT</td>
</tr>
<tr>
<td style=”text-align: center;” width=”79″>)</td>
<td style=”text-align: center;” width=”87″>(/+</td>
<td style=”text-align: center;” width=”95″>PQRT-</td>
</tr>
<tr>
<td style=”text-align: center;” width=”79″>*</td>
<td style=”text-align: center;” width=”87″>(*</td>
<td style=”text-align: center;” width=”95″>PQRT-+/</td>
</tr>
<tr>
<td style=”text-align: center;” width=”79″>U</td>
<td style=”text-align: center;” width=”87″>)*</td>
<td style=”text-align: center;” width=”95″>PQRT-+/U</td>
</tr>
<tr>
<td style=”text-align: center;” width=”79″>)</td>
<td style=”text-align: center;” width=”87″></td>
<td style=”text-align: center;” width=”95″>PQRT-+/U*</td>
</tr>
</tbody>
</table>
<p> </p>
<h3 style=”text-align: center;”><span id=”Short_Answer_Type_Questions-II3_marks_each”><span style=”color: #0000ff;”>Short Answer Type Questions-II[3 marks each]</span></span></h3>
<p> </p>
<p><strong><span style=”color: #eb4924;”>Question 1.</span></strong><br>
Write the definition of a member function Pop ()<br>
in C++, to delete a book from a dynamic stack of TEXTBOOKS considering the following code is already included in the program.</p>
<pre>Struct TEXTBOOKS
{
Char ISBN [20]; Char TITLE [80]; TEXTBOOKS *Link;
};
class STACK
{
TEXTBOOKS *Top;
public :
STACK () {Top = NULL;}
void Push ();
. void pop );
-STACK ();
};</pre>
<p><strong><span style=”color: #008000;”>Answer:</span></strong></p>
<pre>void STACK : : POP ()
{
if (Top ! = NULL)
{
TEXTBOOKS *Temp;
Temp=Top;
cout<< TOP- >ISBN<<Top-
TITLE<<”delected”<<endl;
Top=Top-Link;
delete Temp;
}
else
cout<<”Stack Empty”<<endl;
}</pre>
<p><strong>OR</strong><br>
Any other correct equivalent function definition</p>
<p><strong><span style=”color: #eb4924;”>Question 2.</span></strong><br>
Write the defintion of a member function PUSH () in C+ +, to add a new book in a dynamic stack of BOOKS considering the following code is already included in the program :</p>
<pre>struct BOOKS
{
Char ISBN [20]; TITLE[80];
BOOKS *Link;
};
class STACK
{
BOOKS *Top;
public :
STACK () {Top = NULL;}
void PUSH ();
Void POP ();
-STACK ();
};</pre>
<p><strong><span style=”color: #008000;”>Answer:</span></strong></p>
<pre>void STACK :: PUSH ()
{
BOOKS *Temp;
Temp=New BOOKS;
gets (Temp->ISBN);
gets (Temp->TITLE);
Temp->Link =Top;
Top=Temp;
}</pre>
<p><strong>OR</strong><br>
Any other correct equivalent function definition</p>
<p><strong><span style=”color: #eb4924;”>Question 3.</span></strong><br>
Convert the expression (A-5)*6+(10/B)/2 to corresponding postfix expression. Also show the status of operator stack after each step.<br>
<strong><span style=”color: #008000;”>Answer:</span></strong><br>
((A-5)*6+(10/B)/2)</p>
<table style=”height: 847px;” border=”2″ width=”421″>
<tbody>
<tr>
<td width=”90″>
<p style=”text-align: center;”>Scanned</p>
<p style=”text-align: center;”>Elements</p>
</td>
<td style=”text-align: center;” width=”96″>Stack Status</td>
<td style=”text-align: center;” width=”149″>Output</td>
</tr>
<tr>
<td width=”90″>(<p></p>
<p>(</p>
<p>A</p>
<p>–</p>
<p>5</p>
<p>)</p>
<p>*</p>
<p>6</p>
<p>+</p>
<p>(</p>
<p>10</p>
<p>/</p>
<p>B</p>
<p>)</p>
<p>/</p>
<p>2</p>
<p>)</p></td>
<td width=”96″>(<p></p>
<p>((</p>
<p>((</p>
<p>((-</p>
<p>((-</p>
<p>(</p>
<p>(*</p>
<p>(*</p>
<p>(+</p>
<p>(+(</p>
<p>(+(</p>
<p>(+(/</p>
<p>(+(/</p>
<p>(+</p>
<p>(+/</p>
<p>(+/</p></td>
<td width=”149″> <p></p>
<p> </p>
<p> </p>
<p>A</p>
<p>A</p>
<p>A, 5</p>
<p>A, 5,-</p>
<p>A, 5,-</p>
<p>A, 5, -, 6</p>
<p>A, 5, -, 6*</p>
<p>A, 5,-, 6,*</p>
<p>A, 5, 6, *, 10</p>
<p>A, 5, -, 6, *, 10</p>
<p>A, 5, 6, *, 10, B</p>
<p>A, 5,-, 6,10, B/</p>
<p>A, 5, 6,10, B J</p>
<p>A, 5,-, 6, *, 10, B/,2</p>
<p>A,5,-,6,M0,By,2y,+</p></td>
</tr>
</tbody>
</table>
<p>The correspondence postfix expression is A, 5, 6, 10, B, /,2, /,+</p>
<h3 style=”text-align: center;”><span id=”Long_Answer_Type_Questions4_marks_each”><span style=”color: #0000ff;”>Long Answer Type Questions[4 marks each]</span></span></h3>
<p><strong><span style=”color: #eb4924;”>Question 1.</span></strong><br>
Convert the following Infix expression to its equivalent Postfix expression, showing the stack contents for each step of conversion.<br>
A/(B+C)*D-E<br>
<strong><span style=”color: #008000;”>Answer:</span></strong><br>
A/ (B + C) *D-E</p>
<table border=”2″>
<tbody>
<tr>
<td style=”text-align: center;” width=”182″>Element</td>
<td style=”text-align: center;” width=”182″>Stack</td>
<td style=”text-align: center;” width=”182″>Expression</td>
</tr>
<tr>
<td style=”text-align: center;” width=”182″>A<p></p>
<p>/</p>
<p>(</p>
<p>B</p>
<p>+</p>
<p>C</p>
<p>)</p>
<p>★</p>
<p>D</p>
<p>–</p>
<p>E</p></td>
<td style=”text-align: center;” width=”182″>(<p></p>
<p>(/</p>
<p>(/C</p>
<p>(/c</p>
<p>(/c+</p>
<p>(/c+</p>
<p>(*</p>
<p>(*</p>
<p>(-</p>
<p>(-</p></td>
<td width=”182″>
<p style=”text-align: center;”>A</p>
<p style=”text-align: center;”>A</p>
<p style=”text-align: center;”>A</p>
<p style=”text-align: center;”>AB</p>
<p style=”text-align: center;”>AB</p>
<p style=”text-align: center;”>ABC</p>
<p style=”text-align: center;”>ABC+</p>
<p style=”text-align: center;”>ABC+/</p>
<p style=”text-align: center;”>ABC+/D</p>
<p style=”text-align: center;”>ABC+/D*</p>
<p style=”text-align: center;”>ABC+/D*E-</p>
</td>
</tr>
</tbody>
</table>
<p><strong><span style=”color: #eb4924;”>Question 2.</span></strong><br>
Write definition for a function DISPMID (int A[][5], int R, int C) in C+ + to display the elements of middle row<br>
and middle column from a two dimensional array A having R number of rows and C number of columns.<br>
For example, if the content of array is as follows:</p>
<table border=”2″>
<tbody>
<tr>
<td style=”text-align: center;” width=”65″>215</td>
<td style=”text-align: center;” width=”64″>912</td>
<td style=”text-align: center;” width=”64″>516</td>
<td style=”text-align: center;” width=”64″>401</td>
<td style=”text-align: center;” width=”65″>515</td>
</tr>
<tr>
<td style=”text-align: center;” width=”65″>103</td>
<td style=”text-align: center;” width=”64″>901</td>
<td style=”text-align: center;” width=”64″>921</td>
<td style=”text-align: center;” width=”64″>802</td>
<td style=”text-align: center;” width=”65″>601</td>
</tr>
<tr>
<td style=”text-align: center;” width=”65″>285</td>
<td style=”text-align: center;” width=”64″>209</td>
<td style=”text-align: center;” width=”64″>609</td>
<td style=”text-align: center;” width=”64″>360</td>
<td style=”text-align: center;” width=”65″>172</td>
</tr>
</tbody>
</table>
<p>The function should display the following as output:<br>
103 901 921 802<br>
601 516 921 609<br>
<strong><span style=”color: #008000;”>Answer:</span></strong></p>
<pre>void DISPMID (int A[] [5] , int R, int C)
{
int mid = (R+C)/2;
for (int i=0; i<c; i++)
{
Cout << A[mid] [i]<<””;
} cout<<endl;
for (int i=0; i<R; i++)
cout << A[i][mid]<<””;
}</pre>
<p><strong><span style=”color: #eb4924;”>Question 3.</span></strong><br>
Convert the following Infix expression to its equivalent Postfix expression, showing the stack contents for each step of conversion.<br>
P/(Q-R)*S+T<br>
<strong><span style=”color: #008000;”>Answer:</span></strong><br>
P/(Q-R)*S+T<br>
BODMAS : PQR-/S*T+<br>
PQR-/S*T+</p>
<table border=”2″>
<tbody>
<tr>
<td style=”text-align: center;” width=”182″>Element</td>
<td style=”text-align: center;” width=”181″>Stack</td>
<td style=”text-align: center;” width=”183″>Expression</td>
</tr>
<tr>
<td width=”182″>
<p style=”text-align: center;”>P</p>
<p style=”text-align: center;”>/</p>
<p style=”text-align: center;”>(</p>
<p style=”text-align: center;”>Q</p>
<p style=”text-align: center;”>–</p>
<p style=”text-align: center;”>R</p>
<p style=”text-align: center;”>)</p>
<p style=”text-align: center;”>*</p>
<p style=”text-align: center;”>S</p>
<p style=”text-align: center;”>+</p>
<p style=”text-align: center;”>T</p>
<p style=”text-align: center;”>)</p>
</td>
<td style=”text-align: center;” width=”181″>(<p></p>
<p>(/</p>
<p>(/c</p>
<p>(/c</p>
<p>(/c-</p>
<p>(/c-</p>
<p>(/</p>
<p>(*</p>
<p>(*</p>
<p>(+</p>
<p>(+</p></td>
<td width=”183″>
<p style=”text-align: center;”>P</p>
<p style=”text-align: center;”>P</p>
<p style=”text-align: center;”>P</p>
<p style=”text-align: center;”>PQ</p>
<p style=”text-align: center;”>PQ</p>
<p style=”text-align: center;”>PQR</p>
<p style=”text-align: center;”>PQR-</p>
<p style=”text-align: center;”>PQR-/</p>
<p style=”text-align: center;”>PQR-/S</p>
<p style=”text-align: center;”>PQR-/S*</p>
<p style=”text-align: center;”>PQR-/S*T</p>
<p style=”text-align: center;”>PQR-/S*T+</p>
</td>
</tr>
</tbody>
</table>
<p><strong><span style=”color: #eb4924;”>Question 4.</span></strong><br>
Convert the following infix expression to its equivalent postfix expression, showing the stack contents for each step of conversion:<br>
X/Y+U*(V-W)<br>
<strong><span style=”color: #008000;”>Answer:</span></strong><br>
X / Y + U* (V – W) = ((X / Y) + (U * (V – W)))</p>
<table style=”height: 565px;” border=”2″ width=”343″>
<tbody>
<tr>
<td style=”text-align: center;” width=”88″>Element</td>
<td style=”text-align: center;” width=”86″>Stack</td>
<td style=”text-align: center;” width=”88″>Postfix</td>
</tr>
<tr>
<td width=”88″>(</td>
<td width=”86″></td>
<td width=”88″></td>
</tr>
<tr>
<td width=”88″>(</td>
<td width=”86″></td>
<td width=”88″></td>
</tr>
<tr>
<td width=”88″>X</td>
<td width=”86″></td>
<td width=”88″>X</td>
</tr>
<tr>
<td width=”88″>/</td>
<td width=”86″>/</td>
<td width=”88″>X</td>
</tr>
<tr>
<td width=”88″>Y</td>
<td width=”86″>/</td>
<td width=”88″>XY</td>
</tr>
<tr>
<td width=”88″>)</td>
<td width=”86″></td>
<td width=”88″>XY/</td>
</tr>
<tr>
<td width=”88″>+</td>
<td width=”86″>+</td>
<td width=”88″>XY/</td>
</tr>
<tr>
<td width=”88″>(</td>
<td width=”86″>+</td>
<td width=”88″>XY/</td>
</tr>
<tr>
<td width=”88″>U</td>
<td width=”86″>+</td>
<td width=”88″>XY/U</td>
</tr>
<tr>
<td width=”88″>*</td>
<td width=”86″>+ *</td>
<td width=”88″>XY/U</td>
</tr>
<tr>
<td width=”88″>(</td>
<td width=”86″>+ *</td>
<td width=”88″>XY/U</td>
</tr>
<tr>
<td width=”88″>V</td>
<td width=”86″>+ *</td>
<td width=”88″>XY/UV</td>
</tr>
<tr>
<td width=”88″>–</td>
<td width=”86″>+ *-</td>
<td width=”88″>XY/UV</td>
</tr>
<tr>
<td width=”88″>W</td>
<td width=”86″>+ *-</td>
<td width=”88″>XY/UVW</td>
</tr>
<tr>
<td width=”88″>)</td>
<td width=”86″>+ *</td>
<td width=”88″>XY/UVW-</td>
</tr>
<tr>
<td width=”88″>)</td>
<td width=”86″>+</td>
<td width=”88″>XY/UVW-*</td>
</tr>
<tr>
<td width=”88″>)</td>
<td width=”86″>it</td>
<td width=”88″>XY/UVW-* +</td>
</tr>
</tbody>
</table>
<p>OR</p>
<table style=”height: 445px;” border=”2″ width=”331″>
<tbody>
<tr>
<td style=”text-align: center;” width=”87″>Element</td>
<td style=”text-align: center;” width=”86″>Stack</td>
<td style=”text-align: center;” width=”87″>Postfix</td>
</tr>
<tr>
<td width=”87″>X</td>
<td width=”86″></td>
<td width=”87″>X</td>
</tr>
<tr>
<td width=”87″>/</td>
<td width=”86″>/</td>
<td width=”87″>X</td>
</tr>
<tr>
<td width=”87″>Y</td>
<td width=”86″>/</td>
<td width=”87″>XY</td>
</tr>
<tr>
<td width=”87″>+</td>
<td width=”86″>+</td>
<td width=”87″>XY/</td>
</tr>
<tr>
<td width=”87″>U</td>
<td width=”86″>+</td>
<td width=”87″>XY/U</td>
</tr>
<tr>
<td width=”87″>*</td>
<td width=”86″>+ *</td>
<td width=”87″>XY/U</td>
</tr>
<tr>
<td width=”87″>(</td>
<td width=”86″>+ *(</td>
<td width=”87″>XY/U</td>
</tr>
<tr>
<td width=”87″>V</td>
<td width=”86″>+ *(</td>
<td width=”87″>XY/UV</td>
</tr>
<tr>
<td width=”87″>–</td>
<td width=”86″>+ *(-</td>
<td width=”87″>XY/UV</td>
</tr>
<tr>
<td width=”87″>w</td>
<td width=”86″>+ ‘(-</td>
<td width=”87″>XY/UVW</td>
</tr>
<tr>
<td width=”87″>)</td>
<td width=”86″>+ *</td>
<td width=”87″>XY/UVW-</td>
</tr>
<tr>
<td width=”87″></td>
<td width=”86″></td>
<td width=”87″>XY/UW-*</td>
</tr>
<tr>
<td width=”87″></td>
<td width=”86″></td>
<td width=”87″>XY/UVW-* +</td>
</tr>
</tbody>
</table>
<p><strong>OR</strong></p>
<p>Any other method or converting the given Infix expression to its equivalent Postfix expression showing stack contents</p>
<p><strong><span style=”color: #eb4924;”>Question 5.</span></strong><br>
Evaluate the following postfix expression using stack and show the contents after excecution of each.<br>
<strong><span style=”color: #008000;”>Answer:</span></strong><br>
Operations : 470,5,4,∧,25,/,6,*</p>
<table style=”height: 504px;” border=”2″ width=”424″>
<tbody>
<tr>
<td style=”text-align: center;” width=”43″>S. No.</td>
<td style=”text-align: center;” width=”51″>Symbol</td>
<td style=”text-align: center;” width=”95″>Operation</td>
<td style=”text-align: center;” width=”64″>Stack</td>
<td style=”text-align: center;” width=”47″>Result</td>
</tr>
<tr>
<td width=”43″>1</td>
<td width=”51″>470</td>
<td width=”95″>push(470)</td>
<td width=”64″>470</td>
<td width=”47″></td>
</tr>
<tr>
<td width=”43″>2</td>
<td width=”51″>5</td>
<td width=”95″>push(5)</td>
<td width=”64″>470,5</td>
<td width=”47″></td>
</tr>
<tr>
<td width=”43″>3</td>
<td width=”51″>4</td>
<td width=”95″>push(4)</td>
<td width=”64″>470,5,4</td>
<td width=”47″></td>
</tr>
<tr>
<td width=”43″>4</td>
<td width=”51″>/N</td>
<td width=”95″>P°P(4)</td>
<td width=”64″>470,5</td>
<td width=”47″></td>
</tr>
<tr>
<td width=”43″>0</td>
<td width=”51″></td>
<td width=”95″>pop(5)</td>
<td width=”64″>470</td>
<td width=”47″></td>
</tr>
<tr>
<td width=”43″></td>
<td width=”51″></td>
<td width=”95″>perform(5∧4)</td>
<td width=”64″></td>
<td width=”47″></td>
</tr>
<tr>
<td width=”43″></td>
<td width=”51″></td>
<td width=”95″>push(625)</td>
<td width=”64″>470,625</td>
<td width=”47″></td>
</tr>
<tr>
<td width=”43″>5</td>
<td width=”51″>25</td>
<td width=”95″>push(25)</td>
<td width=”64″>470,625,25</td>
<td width=”47″></td>
</tr>
<tr>
<td width=”43″>6</td>
<td width=”51″>/</td>
<td width=”95″>pop(25)</td>
<td width=”64″>470,625</td>
<td width=”47″></td>
</tr>
<tr>
<td width=”43″></td>
<td width=”51″></td>
<td width=”95″>pop(625)</td>
<td width=”64″>470</td>
<td width=”47″></td>
</tr>
<tr>
<td width=”43″></td>
<td width=”51″></td>
<td width=”95″>perform(625/25)</td>
<td width=”64″>470</td>
<td width=”47″></td>
</tr>
<tr>
<td width=”43″></td>
<td width=”51″></td>
<td width=”95″>push(25)</td>
<td width=”64″>470,25</td>
<td width=”47″></td>
</tr>
<tr>
<td width=”43″>7</td>
<td width=”51″>6</td>
<td width=”95″>push(6)</td>
<td width=”64″>470,25,6</td>
<td width=”47″></td>
</tr>
<tr>
<td width=”43″>8</td>
<td width=”51″>*</td>
<td width=”95″>pop(6)</td>
<td width=”64″>470,25</td>
<td width=”47″></td>
</tr>
<tr>
<td width=”43″></td>
<td width=”51″></td>
<td width=”95″>pop(25)</td>
<td width=”64″>470</td>
<td width=”47″></td>
</tr>
<tr>
<td width=”43″></td>
<td width=”51″></td>
<td width=”95″>perform(25*6)</td>
<td width=”64″>470</td>
<td width=”47″></td>
</tr>
</tbody>
</table>
<p><strong><span style=”color: #eb4924;”>Question 6.</span></strong><br>
Write member functions to perform POP and PUSH operations in a dynamically allocated stack containing the objects of the following structure:</p>
<pre>struct Game
{ char Gamename[30];
int numofplayer;
Game *next; } ;</pre>
<p><strong><span style=”color: #008000;”>Answer:</span></strong></p>
<pre>struct Game
{
char Gamename[3 0] ;
int numofplayer;
Game *next;
};
class Stack { Game *Top;
public :
Stack ()
{
Top = NULL;
}
void Push();
void Pop();
void display();
-Stack();
} ;
void Stack::Push()
{
Game *temp = new Game;
cout<<”Enter Data : “; gets(temp->Gamename);
cin>>temp->numofplayer;
temp->next =Top;
Top = temp;
}
void Stack:: Pop()
{
if ( Top != NULL)
{
Game *temp = Top;
cout<Gamename<<” Deleted”; Top = Top->next;
delete temp;
}
else
cout<<”Stack is empty….”;
}</pre>
<p><strong><span style=”color: #eb4924;”>Question 7.</span></strong><br>
Write a function PUSHBOOK() in C++ to perform insert operation on Dynamic Stack, which contains Book_no and Book_Title. Consider the following definition of NODE, while writing your C+ + code,</p>
<pre>struct NODE
{
int Book_No ;
char Book_Title [20];
NODE * Next;
};</pre>
<p><strong><span style=”color: #008000;”>Answer:</span></strong></p>
<pre>Void PUSHBOOK (NODE *TOP> int Book_No, char B Title [20])
{
NODE*temp;
temp=new NODE;
temp —> Book_No=Book_No;
Strcpy (temp —> Book_Title, B Title) ;
temp –> Next=NULL ;
if (Top==NULL)
Top=temp;
else
{
temp —> Next=top;
Top==temp;
}
}</pre>
<p><strong><span style=”color: #eb4924;”>Question 8.</span></strong><br>
Write a function POPBOOK( ) in C++ to perform delete operation from a Dynamic Stack, which contains Bno and Title. Consider the following definition of NODE, while writing your C++code.</p>
<pre>struct NODE
{
int Bno;
char Title[20] ;
NODE * Link;
} ;</pre>
<p><strong><span style=”color: #008000;”>Answer:</span></strong></p>
<pre>node*PopBOOK(node*TOP int Bno, char B Title [20])
{
node*temp;
temp=new node;
temp —>Bno=Bno;
strcpy (temp —>Title, B Title);
temp ->link=NULL:
if (TOP==NULL)
Top=Temp;
else
{
temp —>link=Top;
TOP==temp;
}
}</pre>
<p><strong><span style=”color: #eb4924;”>Question 9.</span></strong><br>
Write the definition of a member function push() for a class Library in C++ to insert a book information in a dynamically allocated strack of books considering the following code is already written as a part of the program</p>
<pre>struct book
{
int bookid;
char bookname[20];
book*next;
} ;
class Library
{
book*top;
public
Library()
{
top=NULL;
}
void push();
void pop();
void disp() ;
-Library();
};</pre>
<p><strong><span style=”color: #008000;”>Answer:</span></strong></p>
<pre>void Library: :push()
{
book*nptr;
nptr=new book;
cout<<”Enter values for bookid and bookname”; cin> >nptr->bookid;
gets(nptr->bookname);
nptr->next =NULL;
if (top==NULL)
top=nptr;
else
{
nptr->next=top,
top=nptr;
}
}</pre>
<p><strong><span style=”color: #eb4924;”>Question 10.</span></strong><br>
Convert the following Infix expression to its equivalent Postfix expression, showing the stack contents for each step of conversion:<br>
U * V + R / (S-T)<br>
<strong><span style=”color: #008000;”>Answer:</span></strong><br>
U*V + R/(S-T)</p>
<table style=”height: 545px;” border=”2″ width=”311″>
<tbody>
<tr>
<td style=”text-align: center;” width=”85″>Element</td>
<td style=”text-align: center;” width=”84″> Stack</td>
<td style=”text-align: center;” width=”85″>Postfix</td>
</tr>
<tr>
<td width=”85″>(</td>
<td width=”84″></td>
<td width=”85″></td>
</tr>
<tr>
<td width=”85″>(</td>
<td width=”84″></td>
<td width=”85″></td>
</tr>
<tr>
<td width=”85″>U</td>
<td width=”84″></td>
<td width=”85″>U</td>
</tr>
<tr>
<td width=”85″>*</td>
<td width=”84″>*</td>
<td width=”85″></td>
</tr>
<tr>
<td width=”85″>V</td>
<td width=”84″></td>
<td width=”85″>UV</td>
</tr>
<tr>
<td width=”85″>)</td>
<td width=”84″></td>
<td width=”85″>UV*</td>
</tr>
<tr>
<td width=”85″>+</td>
<td width=”84″>+</td>
<td width=”85″></td>
</tr>
<tr>
<td width=”85″>(</td>
<td width=”84″></td>
<td width=”85″></td>
</tr>
<tr>
<td width=”85″>R</td>
<td width=”84″></td>
<td width=”85″>UV*R</td>
</tr>
<tr>
<td width=”85″>/</td>
<td width=”84″>+/</td>
<td width=”85″></td>
</tr>
<tr>
<td width=”85″>(</td>
<td width=”84″></td>
<td width=”85″></td>
</tr>
<tr>
<td width=”85″>S</td>
<td width=”84″></td>
<td width=”85″>UV*RS</td>
</tr>
<tr>
<td width=”85″>–</td>
<td width=”84″>+/-</td>
<td width=”85″></td>
</tr>
<tr>
<td width=”85″>T</td>
<td width=”84″></td>
<td width=”85″>UV*RST</td>
</tr>
<tr>
<td width=”85″>)</td>
<td width=”84″></td>
<td width=”85″>UV*RST-</td>
</tr>
<tr>
<td width=”85″>)</td>
<td width=”84″></td>
<td width=”85″>UV*RST-/</td>
</tr>
<tr>
<td width=”85″>)</td>
<td width=”84″></td>
<td width=”85″>UV*RST-/+</td>
</tr>
</tbody>
</table>
<p><strong>OR</strong></p>
<table style=”height: 392px;” border=”2″ width=”304″>
<tbody>
<tr>
<td width=”85″>U</td>
<td width=”84″></td>
<td width=”85″>U</td>
</tr>
<tr>
<td width=”85″> *</td>
<td width=”84″>*</td>
<td width=”85″>U</td>
</tr>
<tr>
<td width=”85″>V</td>
<td width=”84″>*</td>
<td width=”85″>UV</td>
</tr>
<tr>
<td width=”85″>+</td>
<td width=”84″>+</td>
<td width=”85″>UV*</td>
</tr>
<tr>
<td width=”85″>R</td>
<td width=”84″>+</td>
<td width=”85″>UV*R</td>
</tr>
<tr>
<td width=”85″>/</td>
<td width=”84″>+/</td>
<td width=”85″>UV*R</td>
</tr>
<tr>
<td width=”85″>(</td>
<td width=”84″>+/(</td>
<td width=”85″>UV*R</td>
</tr>
<tr>
<td width=”85″>S</td>
<td width=”84″>+/(</td>
<td width=”85″>UV*RS</td>
</tr>
<tr>
<td width=”85″>–</td>
<td width=”84″>+/(-</td>
<td width=”85″>UV*RS</td>
</tr>
<tr>
<td width=”85″>T</td>
<td width=”84″>+/(-</td>
<td width=”85″>UV*RST</td>
</tr>
<tr>
<td width=”85″>)</td>
<td width=”84″>+/</td>
<td width=”85″>UV’RST-</td>
</tr>
<tr>
<td width=”85″></td>
<td width=”84″>+</td>
<td width=”85″>UV’RST-/</td>
</tr>
<tr>
<td width=”85″></td>
<td width=”84″></td>
<td width=”85″>UV*RST-/+</td>
</tr>
</tbody>
</table>
<p><strong>OR</strong></p>
<p>Any other method for converting the given Infix expression to its equivalent Postfix expression showing stack contents.</p>
<p><a class=”button-red” title=”NCERT Solutions Home Page” href=”http://www.learncbse.in/ncert-solutions-2/”>NCERT Solutions</a><a class=”button-blue” title=”NCERT Solutions for Class 12 Computer Science (C++)” href=”http://www.learncbse.in/ncert-solutions-class-12-computer-science-c/”>Computer science</a><a class=”button-blue” title=”NCERT Solutions for Class 12 English” href=”http://www.learncbse.in/ncert-solutions-for-class-12-english/”>English</a><a class=”button-blue” title=”NCERT Solutions for Class 12 Hindi” href=”http://www.learncbse.in/ncert-solutions-class-12-hindi-core/”>Hindi</a><a class=”button-blue” title=”NCERT Solutions for Class 12 Humanities” href=”http://www.learncbse.in/cbse-class-12-humanities/”>Humanities</a><a class=”button-blue” title=”NCERT Solutions for Class 12 Commerce” href=”http://www.learncbse.in/cbse-class-12-commerce/”>Commerce</a><a class=”button-red” title=”CBSE Class 12 Science” href=”http://www.learncbse.in/cbse-class-12-science/”>Science</a></p>
</div>