введите описание изображения здесь
enter code here
class linkedlist{
public:
class listNode{
public:
int data;
listNode* next;
listNode(int data,listNode* next){
this->data=data;
this->next=next;
}
void printNode(listNode* node,ofstream& outFile){
outFile<<"( "<<node->data<<","<<node<<","<<node->next<<","<<node->next-
>data<<")"<<endl;
}
};
// listNode* listHead;
// listNode* listHead(){
// return new listNode(-9999,NULL);
// }
listNode* findSpot(listNode* listHead,listNode* newNode){
listNode* spot=listHead;
while(spot->next!=NULL && spot->next->data<newNode->data)
spot=spot->next;
return spot;
}
void listInsert(listNode* listHead,listNode* newNode){
listNode* spot=findSpot(listHead,newNode);
newNode->next=spot->next;
spot->next=newNode;
}
void printList(listNode* listHead,ofstream& outFile){
listNode* c=listHead;
outFile<<"listHead -> ";
while(c->next!=NULL){
outFile<<"( "<<c->data<<","<<c<<","<<c->next<<","<<c->next->data<<") -> ";
c=c->next;
}
outFile<<" NULL "<<endl;
}
void constructLL(linkedlist::listNode* listHead,ifstream& inFile,ofstream& outFile2){
int a;
cout<<listHead->data<<endl;
while(inFile>>a){
listNode* newNode=new listNode(a,NULL);
listInsert(listHead,newNode);
printList(listHead,outFile2);
}
}
listNode* findMiddleNode(listNode* listHead,ofstream& outFile2){
listNode* walk1=listHead;
listNode* walk2=listHead;
listHead->printNode(walk1, outFile2);
while(walk2!=NULL && walk2->next!=NULL){
walk1=walk1->next;
walk2=walk2->next->next;
}
return walk1;
}
};
int main(int argc ,char* argv[]) {
ifstream inFile(argv[1]);
ofstream outFile1(argv[2]);
ofstream outFile2(argv[3]);
// linkedlist list;
// list.listHead();
cout<<"123";
linkedlist:: listNode listHead(-9999,NULL);
// list.sethead(-9999);
// listHead=new listNode(-9999,NULL);
// cout<<list.gethead();
constructLL(listHead,inFile,outFile2);
// printList(listHead,outFile1);
// listNode* middleNode=findMiddleNode(listHead,outFile2);
// listHead->printNode(middleNode,outFile1);
inFile.close();
outFile1.close();
outFile2.close();
return 0;
}