Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning PostgreSQL On The Cloud Simplifying Database As A Service On Cloud Platforms

Authors: Baji Shaik ,Avinash Vallarapu

1st Edition

1484234464, 978-1484234464

More Books

Students also viewed these Databases questions

Question

Define Administration?

Answered: 1 week ago

Question

Define Decision making

Answered: 1 week ago

Question

What are the major social responsibilities of business managers ?

Answered: 1 week ago

Question

What are the skills of management ?

Answered: 1 week ago