怎么改可以正确的输入输出链表
求指点修改
头文件
#ifndef a333_H_INCLUDED
#define a333_H_INCLUDED
#include<iostream>
using namespace std;
class Node{
public:
Node();
void SetNext(Node *p);
int Getd();
Node *GetNext();
~Node();
private:
int data;
Node *next;
};
class Link{
public:
Link();
void LinkGet(int n);
void Linkprint();
Node *GetHead();
~Link();
private:
Node *Head;
int num;
};
#endif // 333_H_INCLUDED
函数构造
#include<iostream>
#include"333.h"
using namespace std;
Node::Node(){
cin>>data;
next=NULL;
}
void Node::SetNext( Node * p ){
next=p;
}
int Node::Getd (){
return data ;
}
Node *Node::GetNext (){
return next;
}
Node::~Node (){
cout<<data<<"被析构!"<<endl;
}
Link::Link(){
Head=NULL;
num=0;
}
void Link::LinkGet(int n){
Node *p,*pp;
for(int i=0;i<n;i++){
p=new Node;
pp=Head;
while(p->Getd() > pp->GetNext()->Getd() && pp->GetNext()){
pp=pp->GetNext();
}
if (pp == Head && pp->Getd() > p->Getd()){
p->SetNext(Head);
Head->SetNext(p);
}
else{
p->SetNext(pp->GetNext());
pp->SetNext(p->GetNext());
}
}
}
void Link::Linkprint(){
Node *p;
p=Head;
while(p->GetNext()!=NULL)
{
cout<<p->Getd();
p=p->GetNext();
}
cout<<endl;
}
Node *GetHead();
Link::~Link(){
}
主函数
#include <iostream>
#include"333.h"
using namespace std;
int main()
{
Link l1;
int num;
cin>>num;
l1.LinkGet(num);
l1.Linkprint();
return 0;
}