Question: plz answer part a and b separately Q3 A) . Implement Stack using singly linklist. Define the PUSH(int value) & POP() functions to insert and
plz answer part a and b separately
Q3
A)
. Implement Stack using singly linklist. Define the PUSH(int value) & POP() functions to insert and delete node from the top of link list. (Marks 12)
INSTRUCTIONS:
- The stack should contain maximum 5 nodes.
- If user push 6th node then delete 3 nodes from stack.
B)
Let pointer1 and pointer2 are two pointers of type node. Both are NULL initially.
Now consider the code given below (Marks 12)
void fun_ques06(int n)
{
int i, data;
struct node *newNode;
if(n >= 1)
{
pointer1 = (struct node *)malloc(sizeof(struct node));
if(pointer1 != NULL)
{
cout<<"Enter data: ";
cin>>data;
pointer1->data = data;
pointer1->prev = NULL;
pointer1->next = NULL;
pointer2 = pointer1;
for(i=2; i<=n; i++)
{
newNode = (struct node *)malloc(sizeof(struct node));
if(newNode != NULL)
{
cout<<"Enter data ";
cin>>data;
newNode->data = data;
newNode->prev = pointer2;
newNode->next = NULL;
pointer2->next = newNode;
pointer2= newNode;
}
else
{
cout<<"Error 01";
break;
}
}
}
else
{
cout<<"Error 02";
}
}
else
{
cout<<"Error 3"<
}
}
Answer the following questions,
- What task this function/procedure performs?
- Replace appropriate messages against Error 01, Error 02 and Error 3?
- What exactly is the purpose of code in red color?
- What exactly is the purpose of code in green color?
please solve both parts of this question
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
