Professional Documents
Culture Documents
Assignment No. 2: Shantanu Arun Jambhule Roll No: 205 D-Div
Assignment No. 2: Shantanu Arun Jambhule Roll No: 205 D-Div
Assignment No. 2: Shantanu Arun Jambhule Roll No: 205 D-Div
Assignment No. 2
1 Write a program in C++ for counting the number of nodes present in a given singly linked list using
recursive function. 4M CO2 L3
2 Write a program in C++ to generate reverse of strings stored in a doubly linked list. Ex Input: abcd
---> wxyz----> pqrs Output: dcba ---> zyxw ---> srqp 8M CO1 L3
4 The following sequence of operations are performed on stack: PUSH (10), PUSH (20),POP, PUSH
(10) ,PUSH (20) ,POP ,POP, POP, PUSH (20) ,POP Write the final content of stack with representation
of stack content
#include <bits/stdc++.h>
class Node {
public:
int data;
Node* next;
};
new_node->data = new_data;
new_node->next = (*head_ref);
(*head_ref) = new_node;
if (head == NULL) {
return 0;
}
else {
return 1 + getCount(head->next);
int main()
push(&head, 1);
push(&head, 2);
push(&head, 3);
push(&head, 4);
push(&head, 5);
push(&head, 6);
push(&head, 7);
return 0;
OUTPUT :
#include <bits/stdc++.h>
class Node
public:
int data;
Node *next;
Node *prev;
};
temp = current->prev;
current->prev = current->next;
current->next = temp;
current = current->prev;
if(temp != NULL )
*head_ref = temp->prev;
new_node->data = new_data;
new_node->prev = NULL;
new_node->next = (*head_ref);
if((*head_ref) != NULL)
(*head_ref)->prev = new_node ;
(*head_ref) = new_node;
while(node != NULL)
node = node->next;
int main()
push(&head, 123);
push(&head, 456);
push(&head, 789);
push(&head, 1011);
printList(head);
reverse(&head);
printList(head);
return 0;
OUTPUT :