Question
My output files keep coming out empty with no errors. please help debug my code to print the following output. input1.txt: string head world digital
My output files keep coming out empty with no errors. please help debug my code to print the following output.
input1.txt:
string head world digital remove tail remove [2] hello print remove tail
output:
input2.txt:
int tail 23 2 remove [0] 65 5 remove [3] remove [2] 0 45 remove tail 15
output:
2 0 15
input3.txt: char head c remove tail remove tail h w o p e remove head remove tail remove head r
output:
r o w
my code:
#include
template
template
public: linkedlist(); ~linkedlist(); bool isEmpty() { return head == nullptr; } int getSize() { return size; } void addAtHead(T value); void addAtTail(T value); void removeAtHead(); void removeAtTail(); void addAtPos(T value, int pos); void removeAtPos(int pos); void print(); };
template
template
template
template
template
node
template
node
template
while(curr != nullptr) { cout data next;
} }
//outputFile *cu = head; while (cu != nullptr) { cout data next; }*/
template
node
if (pos > size) return; else if (pos == 0) { head = temp; temp->next = cu; } else { for (int i = 0; i next; } prev->next = temp; temp->next = cu; } size++; }
int main() { linkedlist
to get students familiar with Linked List operations and type template. 1. Input files - The first input line will contain a string indicating the data type of the linked list - Options will either be 'string', 'int' or 'char' - Each input file will only contain a single data type - The second input line will indicate how to insert new data into the linked list. - Options will be either 'head' or 'tail'. - If it says 'head', add elements only to the beginning of the linked list for this input file. If it says 'tail', add elements only to the end of the linked list for this input file. - Each input file will only contain a single insert option - Each element will be on its own line. - There are three additional operations: 'remove head', 'remove tail', and 'remove [index]' If the line says 'remove head', remove the first element in the linked list If the line says 'remove tail', remove the last element in the linked list. If the line says 'remove [index], remove the element at [index] in the linked list - If the index is 0 , remove the head of the linkedlist - If the index is equal to or greater than the amount of elements in the linked list, remove the tail of the linkedlist - Otherwise, remove the element at the specified index - Example: linked list currently is hello, computer, science, world - The operation 'remove [1]' would remove computer since its index is 1 - When reading the input, In and should be removed before processing the string. 2. Assumptions - The keywords 'head', 'tail', and 'remove' will never appear as data. - No empty lines, but there can have empty files; empty input files should be empty output files. 3. Output files - The output file should display every element in the linked list on a single line, separated by a space. - Empty input files should result in an empty output file
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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