10 Umair Sarwar 221728
10 Umair Sarwar 221728
EXPERIMENT NO 10
Ability to Conduct
Experiment
Data presentation
Experimental results
Conclusion
#include <iostream>
using namespace std;
class Node
{
public:
int data;
Node *next;
};
void push(Node** head_ref, int new_data)
{
new_node->data = new_data;
new_node->next = (*head_ref);
(*head_ref) = new_node;
}
void insertAfter(Node* prev_node, int new_data)
{
if (prev_node == NULL)
{
cout<<"the given previous node cannot be NULL";
return;
}
new_node->data = new_data;
new_node->next = prev_node->next;
prev_node->next = new_node;
}
new_node->data = new_data;
new_node->next = NULL;
if (*head_ref == NULL)
{
*head_ref = new_node;
return;
}
while (last->next != NULL)
last = last->next;
last->next = new_node;
return;
}
int main()
{
append(&head, 6);
push(&head, 29);
push(&head, 11);
append(&head, 14);
insertAfter(head->next, 50);
return 0;
}
OUTPUT
QUESTION NUMBER 2:
Make a function which deletes node from your linked list at
the tail and write a function to display all the data of your
new linked list
CODE:
#include <iostream>
using namespace std;
struct Node {
int data;
struct Node *prev;
struct Node *next;
};
struct Node* head = NULL;
void insert(int newdata) {
struct Node* newnode = (struct Node*) malloc(sizeof(struct
Node));
newnode->data = newdata;
newnode->prev = NULL;
newnode->next = head;
if(head != NULL)
head->prev = newnode ;
head = newnode;
}
void display() {
struct Node* ptr;
ptr = head;
while(ptr != NULL) {
cout<< ptr->data <<" ";
ptr = ptr->next;
}
}
int main() {
insert(3);
insert(1);
insert(7);
insert(2);
insert(9);
cout<<"The doubly linked list is: ";
display();
return 0;
}
OUTPUT:
No output.
QUESTION NUMBER 3:
CODE:
#include<iostream>
using namespace std;
#include<cstdlib>
struct Node {
int data;
Node* next;
Node(int x)
{
data = x;
next = NULL;
}
};
struct Node* push(struct Node* last, int data)
{
if (last == NULL) {
struct Node* temp
= (struct Node*)malloc(sizeof(struct Node));
temp->data = data;
last = temp;
temp->next = last;
return last;
}
return last;
}
return result;
}
int main()
{
Node* First = NULL;
First = push(First, 1);
First = push(First, 2);
First = push(First, 3);
First = push(First, 4);
First = push(First, 5);
First = push(First, 7);
cout << counter(First);
return 0;
}
CONCLUTION:
In this lab we learn the use of inheritance in classes. We can learn about
public, private, and protected inheritance. also, we learn about constructor
and destructor and learn about methods to use constructor, destructor in
inheritance.