Lab 5 Dsa
Lab 5 Dsa
Lab 5 Dsa
struct Node {
int data;
Node* next;
};
Node* createLL() {
Node* head = nullptr;
Node* ptr = nullptr;
int numNodes, data;
if (head == nullptr) {
head = newNode;
} else {
ptr = head;
while (ptr->next != nullptr) {
ptr = ptr->next;
}
ptr->next = newNode;
}
}
return head;
}
int main() {
Node* head = createLL();
return 0;
}
#include <iostream>
using namespace std;
struct Node
{
int data;
Node *next;
Node(int val)
{
data = val;
next = NULL;
}
};
class Linked_List
{
Node *head;
public:
Linked_List()
{
head = NULL;
}
int odd_sum = 0;
void display()
{
Node *temp = head;
while (temp != NULL)
{
cout << temp->data << "->";
temp = temp->next;
}
cout << "Null";
}
void oddsumprint(){
cout<<endl<<"odd sum is : "<<odd_sum;
}
};
int main()
{
Linked_List list;
cout << "Enter the no. of node : ";
int n;
cin >> n;
list.insert_at_End(n);
return 0;
}
#include <iostream>
using namespace std;
struct Node {
int data;
Node* next;
};
Node* createLL() {
Node* head = nullptr;
Node* ptr = nullptr;
int numNodes, data;
if (head == nullptr) {
head = newNode;
} else {
ptr = head;
while (ptr->next != nullptr) {
ptr = ptr->next;
}
ptr->next = newNode;
}
}
return head;
}
int count = 0;
Node* ptr = head;
while (ptr != nullptr) {
count++;
ptr = ptr->next;
}
ptr = head;
for (int i = count - 1; i >= 0; i--) {
ptr->data = dataArr[i];
ptr = ptr->next;
}
delete[] dataArr;
}
reverseData(head);
cout << "Linked list after reversing the data: " << endl;
display(head);
return 0;
}