Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Could help me fix the error? my project is find the middle node in the linked list. output text file should sorted with ascending order

Could help me fix the error?

my project is find the middle node in the linked list. output text file should sorted with ascending order

please check my code below

#include #include # include #include #include using namespace std;

struct Node { int data; struct Node* next; }; void printMiddle(struct Node *head) { struct Node *slow_ptr = head; struct Node *fast_ptr = head; if (head!=NULL) { while (fast_ptr != NULL && fast_ptr->next != NULL) { fast_ptr = fast_ptr->next->next; slow_ptr = slow_ptr->next; } printf("The middle element is [%d] ", slow_ptr->data); } } void push(struct Node** head_ref, int new_data) { struct Node* new_node = (struct Node*) malloc(sizeof(struct Node)); new_node->data = new_data; new_node->next = (*head_ref); (*head_ref) = new_node; } void printList(struct Node *ptr) { while (ptr != NULL) { printf("%d->", ptr->data); ptr = ptr->next; } printf("NULL "); }

int main() { ofstream file_; file_.open("mytext.txt"); file_ <<"91"<<" "<<"322"<<" "<<"9"<<" "<<10 < file_ <<"77"<<" "<<"8"<<" "<<"999"<<" "<<12 < file_ <<"133"<<" "<<"14" < file_ <<"8"< file_ <<"538"<<" "<<"29"<<" "<<"91" < file_ <<"88" < file_ <<"702"<<" "<<"361" < file_ <<"637" < file_ <<"99" <

file_.close(); std::string line_; ifstream file_("mytext.txt"); if(file_.is_open()) { while(getline(file_, line_)) { std::cout< } file_.close(); } else std::cout<<"file is not open"<< ' '; std::cin.get(); return 0; }

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

Database Systems On GPUs In Databases

Authors: Johns Paul ,Shengliang Lu ,Bingsheng He

1st Edition

1680838482, 978-1680838480

More Books

Students also viewed these Databases questions

Question

Round each of the following to four-figure accuracy. 9.6455

Answered: 1 week ago