Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Trying do this in C++: Also, this is the double linked list I created in the first assignment: Write a program that reads a text

Trying do this in C++:

image text in transcribed

Also, this is the double linked list I created in the first assignment:

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribed

Write a program that reads a text file and outputs a list of all words in alphabetical order. Each word should be displayed with a list of line numbers on which it occurs in the file. Use an AVL binary search tree to store the words seen. Requirements: 1. The program must work for arbitrary large files sizes. 2. You must test the program using the file I will provide. 3. Each node is to have a linked list to store all of the line numbers. Use the list you created in assignment 1. 4. Make the tree a class with the necessary functions. Example: Input Hello Bill, Did you hear about Aunt Betty or about Aunt White? I cannot believe that Output about Aunt believe Betty Bill cannot Did aicima Manama hear Hello or that White you #include #include #include #include /*When data is integer*/ using namespace std; struct Node { int data; Node* next; Node* prev; Node(int value) { data = value; next = NULL; prev = NULL; [}; class DoublyLinkedList { public: DoublyLinkedList(); DoublyLinkedlist(); void insert_front(int); void insert_back(int); int delete_front(); int delete_back(); bool is_empty(); void display(); int length(); private: Node* head; Node* tail; int size; [}; DoublyLinkedList::DoublyLinkedList() { /*Construct a linked list with a null head*/ head = NULL; tail = NULL; size = 0; - - - - - DoublyLinkedlist::~DoublyLinkedList() { Node* temp = head; /*Keep iterating until head is null*/ while (temp != nullptr) { temp = head->next; delete head; head = temp; - - - - - - - - - ---- delete head; //delete head, .- L void DoublyLinkedlist::insert_front(int value) { Node* temp = new Node(value); if (head == NULL) head = tail = temp; else { head->prev = temp; temp->next = head; head = temp; ---- -- size++; Avoid DoublyLinkedList::insert_back(int value) { Node* temp = new Node(value); - - - - - - - - -- - if (tail == NULL) head = tail = temp; else { tail->next = temp; temp->prev = tail; tail = temp; ------------- size++; w - Sint DoublyLinkedList::delete_front() { Si if (!is_empty()) { Node* temp = head; if (head == tail) { i tail == NULL; - - - - - - - - - - - - - = - = - = - = - = - = - = int delValue = temp->data; head = head->next; - = - = - = - = - = - = - = delete temp; - - - - - - - - - - - - size--; - - - - - - - - - - - return delValue; - - - - - - - return 0; - Sint DoublyLinkedList::delete_back() { if (!is_empty()) { Node* temp = tail; if (head == tail) { head == NULL; - - - - - - - - - - - - - - - - - - - - - - - - - - - - int delValue = temp->data; tail->next = NULL; tail = tail->prev; - - - - - - - - - - - - - - - - - delete temp; - - - - - - - - - - - - size--; - - - - - - - - - - return delValue; - - - - - - return 0; - bool DoublyLinkedList::is empty() { - if (size data "; //expection thrown here temp = temp->next; cout #include #include #include /*When data is integer*/ using namespace std; struct Node { int data; Node* next; Node* prev; Node(int value) { data = value; next = NULL; prev = NULL; [}; class DoublyLinkedList { public: DoublyLinkedList(); DoublyLinkedlist(); void insert_front(int); void insert_back(int); int delete_front(); int delete_back(); bool is_empty(); void display(); int length(); private: Node* head; Node* tail; int size; [}; DoublyLinkedList::DoublyLinkedList() { /*Construct a linked list with a null head*/ head = NULL; tail = NULL; size = 0; - - - - - DoublyLinkedlist::~DoublyLinkedList() { Node* temp = head; /*Keep iterating until head is null*/ while (temp != nullptr) { temp = head->next; delete head; head = temp; - - - - - - - - - ---- delete head; //delete head, .- L void DoublyLinkedlist::insert_front(int value) { Node* temp = new Node(value); if (head == NULL) head = tail = temp; else { head->prev = temp; temp->next = head; head = temp; ---- -- size++; Avoid DoublyLinkedList::insert_back(int value) { Node* temp = new Node(value); - - - - - - - - -- - if (tail == NULL) head = tail = temp; else { tail->next = temp; temp->prev = tail; tail = temp; ------------- size++; w - Sint DoublyLinkedList::delete_front() { Si if (!is_empty()) { Node* temp = head; if (head == tail) { i tail == NULL; - - - - - - - - - - - - - = - = - = - = - = - = - = int delValue = temp->data; head = head->next; - = - = - = - = - = - = - = delete temp; - - - - - - - - - - - - size--; - - - - - - - - - - - return delValue; - - - - - - - return 0; - Sint DoublyLinkedList::delete_back() { if (!is_empty()) { Node* temp = tail; if (head == tail) { head == NULL; - - - - - - - - - - - - - - - - - - - - - - - - - - - - int delValue = temp->data; tail->next = NULL; tail = tail->prev; - - - - - - - - - - - - - - - - - delete temp; - - - - - - - - - - - - size--; - - - - - - - - - - return delValue; - - - - - - return 0; - bool DoublyLinkedList::is empty() { - if (size data "; //expection thrown here temp = temp->next; cout

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

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions