Assignment 2
Assignment 2
21-512
Mathematics + Computer Science
Assignment 2.
1/ Code structure:
#include <iostream>
#include <string>
struct Human {
float weight;
std::string gender;
};
int main() {
// Change the value of the integer using pointer dereferencing
*p_i = 20;
// Adding another variable to the node struct in the linked list class
struct Node {
int data;
Node* next;
// New variable added
std::string additionalInfo;
};
class LinkedList {
public:
void printList(Node* node) {
while (node != nullptr) {
std::cout << node->data << " - " << node->additionalInfo << std::endl;
node = node->next;
}
}
};
head->data = 1;
head->additionalInfo = "First Node";
head->next = second;
second->data = 2;
second->additionalInfo = "Second Node";
second->next = third;
third->data = 3;
third->additionalInfo = "Third Node";
third->next = nullptr;
LinkedList ll;
ll.printList(head);
return 0;
}
2/ Screenshots for it and for the output :