c++ 问题 急需高手帮忙

来源:百度知道 编辑:UC知道 时间:2024/05/23 11:06:45
a) opens anASCII file input_data_file.txt that contains one integer per line and stores them in a linked list.
b) sorts the list of numbers using the Bubble sort algorithm. The swapping of the elements should be done through pointer operation only(i.e. do not copy the data themselves).
c) writes the ordered list to output_data_file.txt that contains the integers that should be deleted from the first list(i.e. it may contain numbers that are not in the initial file).
e) writes the resulting list to output_file_2.txt.
3.4号早上8点要交,各位大侠拜托了

懒得写了,睡觉了
你去搜文件读写
链表操作
都有现成的程序,排序就用冒泡好了,简单到不用思考
拼一下就成了

翻译出来的大概是这样!
第一步,打开一个名叫input_data_file.txt的文本文档,此文档里面每行都有一个整数,然后把这些整数存到一个链表(linked list)里。
第二步,通过指针给这些整数按照从小到大的方式排序。
第三步,把排好的顺序输出到output_file_2.txt里面。

#include <iostream>
#include <fstream>
#include <string>
#include <list>

using std::cout;
using std::cin;
using std::endl;

int main()
{
cout<<"please input the input file name:"; //输入文件名
std::string input_file_name;
cin >> input_file_name;
std::string output_file_name;
cout<<"please input the output file name:"; //输出文件名
cin>>output_file_name;

std::list<int> number_list;
//-----------------------读取------------------------
std::ifstream read_file(input_file_name.c_str(),std::ios_base::in);
int n=0;
while(read_file>>