<div class=”entry-content”><h2><span style=”color: #00ccff;”>NCERT Solutions for Class 12 Computer Science (C++) – Queue</span></h2>
<h3 style=”text-align: center;”><span style=”color: #0000ff;”>Long Answer Type Questions [4 marks each]</span></h3>
<p><span style=”color: #eb4924;”><strong>Question 1:</strong></span><br>
Define member function delque() to perform delete operation on a linked queue where each node has the following structure :</p>
<pre style=”padding-left: 30px;”>struct node
{
char name[20]
int marks;
node *link;
};
class queue
{
node *front,‘rear;
public :
queue() {front=rear=NULL;
}
void delque ( );
}; <em><strong>[CBSE Comptt., 2014]</strong></em></pre>
<p><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=”unfilled”><div id=”aswift_1_host” tabindex=”0″ title=”Advertisement” aria-label=”Advertisement” style=”border: none; height: 0px; width: 750px; margin: 0px; padding: 0px; position: relative; visibility: visible; background-color: transparent; display: inline-block; overflow: hidden; opacity: 0;”><iframe id=”aswift_1″ name=”aswift_1″ style=”left: 0px; position: absolute; top: 0px; border: 0px; width: 750px; height: 0px;” sandbox=”allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-top-navigation-by-user-activation” width=”750″ height=”0″ 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=1301505161&pi=t.ma~as.8094000682&w=750&lmt=1672506857&format=750×280&url=https%3A%2F%2Fwww.cbsetuts.com%2Fncert-solutions-class-12-computer-science-c-queue%2F&wgl=1&adsid=ChEIgPvEnQYQ7oKUkIGo7bvHARI9AMmKl4njHNeyl_CqlT8S0OF1tvXPug1x2AUxnh775_uuykilji8AXDA_yNNBbErEKSPW8ts-r1Zo16aalw&uach=WyJXaW5kb3dzIiwiMTAuMC4wIiwieDg2IiwiIiwiMTA4LjAuNTM1OS4xMjUiLFtdLGZhbHNlLG51bGwsIjY0IixbWyJOb3Q_QV9CcmFuZCIsIjguMC4wLjAiXSxbIkNocm9taXVtIiwiMTA4LjAuNTM1OS4xMjUiXSxbIkdvb2dsZSBDaHJvbWUiLCIxMDguMC41MzU5LjEyNSJdXSxmYWxzZV0.&dt=1672585162927&bpp=2&bdt=1765&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=7513581215988&frm=20&pv=1&ga_vid=540223204.1672348852&ga_sid=1672585162&ga_hid=293855606&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=1001&biw=1349&bih=657&scr_x=0&scr_y=0&eid=44759875%2C44759926%2C44759837%2C31071168%2C44779794%2C44780792&oid=2&pvsid=1517157991550493&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=a6wm0THnCM&p=https%3A//www.cbsetuts.com&dtd=19″ data-google-container-id=”a!2″ data-load-complete=”true” data-google-query-id=”CLKU8qPRpvwCFUS9lgodnJIJIA”></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=”unfilled”><div id=”aswift_4_host” tabindex=”0″ title=”Advertisement” aria-label=”Advertisement” style=”border: none; height: 0px; width: 750px; margin: 0px; padding: 0px; position: relative; visibility: visible; background-color: transparent; display: inline-block; overflow: hidden; opacity: 0;”><iframe id=”aswift_4″ name=”aswift_4″ style=”left: 0px; position: absolute; top: 0px; border: 0px; width: 750px; height: 0px;” sandbox=”allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-top-navigation-by-user-activation” width=”750″ height=”0″ 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=1406860139&pi=t.ma~as.8094000682&w=750&lmt=1672506857&format=750×280&url=https%3A%2F%2Fwww.cbsetuts.com%2Fncert-solutions-class-12-computer-science-c-queue%2F&wgl=1&adsid=ChEIgPvEnQYQ7oKUkIGo7bvHARI9AMmKl4njHNeyl_CqlT8S0OF1tvXPug1x2AUxnh775_uuykilji8AXDA_yNNBbErEKSPW8ts-r1Zo16aalw&uach=WyJXaW5kb3dzIiwiMTAuMC4wIiwieDg2IiwiIiwiMTA4LjAuNTM1OS4xMjUiLFtdLGZhbHNlLG51bGwsIjY0IixbWyJOb3Q_QV9CcmFuZCIsIjguMC4wLjAiXSxbIkNocm9taXVtIiwiMTA4LjAuNTM1OS4xMjUiXSxbIkdvb2dsZSBDaHJvbWUiLCIxMDguMC41MzU5LjEyNSJdXSxmYWxzZV0.&dt=1672585162999&bpp=2&bdt=1837&idt=2&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=7513581215988&frm=20&pv=1&ga_vid=540223204.1672348852&ga_sid=1672585162&ga_hid=293855606&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=1289&biw=1349&bih=657&scr_x=0&scr_y=0&eid=44759875%2C44759926%2C44759837%2C31071168%2C44779794%2C44780792&oid=2&pvsid=1517157991550493&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=q92w2sbnvf&p=https%3A//www.cbsetuts.com&dtd=50″ data-google-container-id=”a!5″ data-load-complete=”true” data-google-query-id=”COG98qPRpvwCFUMulgodpokPHg”></iframe></div></ins></div>
<script type=”text/javascript”>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></div>
<pre style=”padding-left: 30px;”>void queue : : delque ()
{
if ( front != NULL)
{
node *Temp = front;
cout << Temp -> name << Temp
->marks;
front = front->link;
delete Temp;
if(front == NULL)
rear = NULL;
}
else
cout << “Queue is empty”;
}
<strong><em>(4 marks for correct program)</em></strong></pre>
<p><span style=”color: #eb4924;”><strong>Question 2:</strong></span><br>
Give the necessary declaration of linked’ implemented Queue containing players information (as defined in the following definition of Node). Also write a user defined function in C++ to delete one Player’s information from the Queue. <em><strong><br>
[CBSE Comptt., 2013]</strong></em></p>
<pre style=”padding-left: 30px;”>struct node
{
int Player No ;
char PlayerName[20];
Node*Link;
}</pre>
<p><strong><span style=”color: #008000;”>Answer:<br>
</span></strong>NODE *QUEUEDEL(Node * front, int val, char val2[ ])</p>
<pre style=”padding-left: 30px;”>{
Node *temp;
if (front ==NULL) <strong>[1]</strong>
cout<<”Queue EMPTY”;
{
else
{
temp=front ;
temp®PlayerNo=val; <strong>[1]</strong>
strcpy (temp®PlayerName, val2);
front=front®Link; <strong>[1]</strong>
delete temp;
}
return (front);
}<strong><em> </em></strong> <strong>[1]</strong></pre>
<p><span style=”color: #eb4924;”><strong>Question 3:</strong></span><br>
Write a function QDELETE ( ) in C++ to perform delete operation on a Linked Queue, which contains Passenger no and Passenger name. Consider the following definition of Node in the code,</p>
<pre style=”padding-left: 30px;”>struct node
{
long int Pno;
char Pname [20];
node *Link;
}; <strong><em> [O.D, 2013]</em></strong></pre>
<p><strong><span style=”color: #008000;”>Answer:<br>
</span></strong>//Function to delete queue elements Node * QUEUE (Node * front, int val, char vail [])</p>
<pre style=”padding-left: 30px;”>{
Node *temp;
if (front == NULL)
cout <<”Queue Empty”;
else
{
temp = front;
temp®Pno=val;
strcpy (temp®Pname, vail);
front = front®Link;
delete temp;
}
return (front);
} <strong> [4]</strong></pre>
<p><span style=”color: #eb4924;”><strong>Question 4:</strong></span><br>
Write a function QINSERT() in C+ + to perform insert operation on a Linked Queue, which contains Client no and Client name. Consider the following definition of NODE in the code of . QINSERT (). <strong> [Delhi, 2013]</strong></p>
<pre style=”padding-left: 30px;”>struct Node
{
long int Cno; // Client No
char Cname [20]; //
Client Name
Node *Next ;
};</pre>
<p><strong><span style=”color: #008000;”>Answer:<br>
</span></strong>Function to Insert element<br>
Node * QINSERT (Node *rear, int val),</p>
<pre style=”padding-left: 30px;”>char val []
{
Node *temp;
temp = new Node;
temp®Cno = val;
strcpy (temp®Cname, val);
temp®NEXT=NULL;
rear®NEXT=temp;
rear=temp;
return (rear);
} <strong>[4]</strong></pre>
<p><span style=”color: #eb4924;”><strong>Question 5:</strong></span><br>
Write a function in C++ to perform Insert operation in a circular Queue containing Layer’s information (represented with the help of an array of structure Player). <em> <strong>[CBSE SQP 2013]</strong></em></p>
<pre style=”padding-left: 30px;”>struct Player
{
long PID; //Player ID
char Pname [20];} //Player Name
Player*Link;
}</pre>
<p><strong><span style=”color: #008000;”>Answer:</span></strong></p>
<pre style=”padding-left: 30px;”>void Insert ( )
{
PLAYER *P = new PLAYER;
cout <<”Enter Player ID & Name”;
cin>>P→PID;
gets (P→ Pname);
P®Link=NULL;
if ((fronts = NULL) && (rear == NULL))
{
front = rear = P;
}
else
{
rear®Link = P;
rear = P;
}
} <strong>[4]</strong></pre>
<p><span style=”color: #eb4924;”><strong>Question 6:</strong></span><br>
Write a function in C++ to perform insert operation in a static circular queue containing book’s information (represented with the help of an array of structure BOOK). <em><strong>[O.D, 2012]</strong></em></p>
<pre style=”padding-left: 30px;”>struct BOOK
{
long Accno; //Book Accession Number char Title[20]; //Book Title
};</pre>
<p><strong><span style=”color: #008000;”>Answer:</span></strong></p>
<pre style=”padding-left: 30px;”>struct BOOK
{
long Accno; char Title [20] ;
int front, rear;
}B [10] ;
void insert()
{
if (r e a r = = s i z e – l & & f r o n t = = 0||front== rear+1)
{
cout<<”\n Circular queue is full”; return;
}
else if(rear==-l)
{
rear++;
front++;
}
else if(rear==size-1)
rear=0;
else
{
rear++;
}
cout<<”Enter Title : ” ;
cin>>B[rear] . Title;
cout<<”Enter Accno : ” ;
cin>>B[rear] . Accno;
} <strong>[4]</strong></pre>
<p><span style=”color: #eb4924;”><strong>Question 7:</strong></span><br>
Write a function in C++ to perform insert operation in a dynamic queue containing DVD’s information (represented with the help of an array of structure DVD). <em><strong>[Delhi, 2012]<br>
</strong></em><strong><span style=”color: #008000;”>Answer:<br>
</span></strong>/*Function in C++ to perform insert in a dynamic queue is given as*/</p>
<pre style=”padding-left: 30px;”>struct DVD
{
long No; // DVD Number
char Title[20]; // DVD Title
DVD *Link
};
void insert(struct DVD *start, char data[20] ) ;
{
DVD *q, *temp;
// Dynamic memory has been allocated for a node
temp=(DVD*)malloc(size of (DVD));
temp=Title[20]=data[20] ;
temp”Next=NULL;
if (start = = NULL) /*Element
inserted at end*/
while (q”Next ! = NULL)
q=q.Next;
q.Next = temp;
} <strong>[4]</strong></pre>
<p><span style=”color: #eb4924;”><strong>Question 8:</strong></span><br>
Write the definition of a member function INSERT() for a class QUEUE in C++, to insert a CUSTOMER in a dynamically allocated Queue of items considering the following code which is already written as a part of the program,</p>
<pre style=”padding-left: 30px;”>struct CUSTOMER
{
int CNO; char CNAME[20];
CUSTOMER *Link;
};
Class QUEUE
{
CUSTOMER *R,*F;
Public:
QUEUE(){R=NULL;F=NULL;}
void INSERT();
void DELETE()
-QUEUE();
}; <strong><em> [CBSE SQP 2013]</em></strong></pre>
<p><strong><span style=”color: #008000;”>Answer:</span></strong></p>
<pre style=”padding-left: 30px;”>void QUEUE : : INSERT ()
{
CUSTOMER*T=New CUSTOMER;
cin>>T>>;
gets(T→CNAME);
//OR cin>>T>>CNAME;
T → LINK = NULL;
if (R==NULL)
{
F=T; R=T;
}
else
{ R → LINK = T; R = T;
}
}</pre>
<p><strong>(1 Mark for correct a new code)</strong><br>
<strong>(1/2 Mark for entering data to new code)</strong><br>
<strong>(1/2Mark for assigning NULL to link of the new code)</strong><br>
<strong>(1/2 Mark for assigning front to the first code as L=T)</strong><br>
<strong>(1/2 Mark for linking the last node to new code as R→Link=T)</strong><br>
<strong>(1 Mark for assign Read to the new code as R=T) </strong></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>