Professional Documents
Culture Documents
Dsa Lab 5 Ahtasham Sajawal 211356
Dsa Lab 5 Ahtasham Sajawal 211356
HEADER FILE
******************************************************************
*************/
#include <iostream>
#include <string>
/
******************************************************************
************
IMPLEMENTATION FILE
******************************************************************
*************/
Node *head;
void insert(int x)
{
Node *temp = new Node();
temp->data = x;
temp->next = head;
head = temp;
}
current=current->next;
count++;
}
return count;
current = current->next;
return true;
}
else
cout<<"\n Search Data do not exists \n";
return false;
}
}
return NULL;
if (node->next == NULL) {
head = node;
return node;
}
Node* node1 = reverse(node->next);
node1->next = node;
node->next = NULL;
return node;
}
int count = 0;
while (current != NULL) {
if (count == indx)
return (current->data);
count++;
current = current->next;
}
}
Node* newNode(int data)
{
Node* new_node = new Node();
new_node->data = data;
new_node->next = NULL;
return new_node;
}
prev = temp;
if (head)
head = head->next;
if (second)
second = second->next;
}
if (carry > 0)
temp->next = newNode(carry);
return res;
}
new_node->data = new_data;
new_node->next = (*head_ref);
(*head_ref) = new_node;
}
/
******************************************************************
************
#include <bits/stdc++.h>
using namespace std;
int main()
{
Node list;
Node* res = NULL;
Node* second = NULL;
head = NULL;
int Size,size, number;
cout<<"What is the size of 1st list: ";
cin>>size;
for(int i = 1; i<=size; i++)
{
cout<<"\nEnter Number: ";
cin>>number;
insert(number);
cout<<"First Linked List = ";
printList(head);
}
search(head, 11);
cout << "COUNT OF NODES = " << getcount(head)<<endl<<endl;
cout << "Data at index 1 = " << getNth(head, 1)<<endl<<endl;
cout << "\nReversed Linked list = ";
reverse(head);
printList(head);
pushFront(&second, 10);
pushFront(&second, 6);
pushFront(&second, 7);
cout<<"Second Linked List is = ";
printList(second);
head = Rev(head);
second = Rev(second);
res = addTwoLists(head, second);
res = Rev(res);
cout << "Resultant list is = ";
printList(res);
return 0;
}
/
******************************************************************
************
OUTPUT
******************************************************************
*************/