Question
Using the following code for creating a linked list, in MAIN, import the data from a file consisting of 150 integers and store them in
Using the following code for creating a linked list, in MAIN, import the data from a file consisting of 150 integers and store them in a linked list.
#include
#include
#include
using namespace std;
struct node
{
int data;
node *next;
};
class linkedList
{
private:
node *head, *tail;
public:
linkedList()
{
head = NULL;
tail = NULL;
}
void insertNode(int n)
{
node *temp = new node;
temp->data = n;
temp->next = NULL;
if(head == NULL)
{
head = temp;
tail = temp;
temp = NULL;
}
else
{
tail->next = temp;
tail = temp;
}
}
void insertHead(int n)
{
node *temp = new node;
temp->data = n;
temp->next = head;
head = temp;
#include
struct node { int data; node *next; };
class linkedList { private: node *head, *tail; public: linkedList() { head = NULL; tail = NULL; } void insertNode(int n) { node *temp = new node; temp->data = n; temp->next = NULL;
if(head == NULL) { head = temp; tail = temp; temp = NULL; } else { tail->next = temp; tail = temp; } } void insertHead(int n) { node *temp = new node; temp->data = n; temp->next = head; head = temp; }
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started