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 #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; }

}

void insertPosition(int position, int n) { node *previous = new node; node *current = new node; node *temp = new node; current = head; for(int i = 1; i < position; i++) { previous = current; current = current->next; } temp->data = n; previous->next = temp; temp->next = current; } void display() { node *temp = new node; temp = head; while(temp != NULL) { cout << temp->data << endl; temp = temp->next; } } };

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!