来自山东理工大学oj的题
一道简单的链表题
#include <iostream>
using namespace std;
struct Node{
int data;
Node *Next;
};
class LinkSq{
private:
int size_;
Node *head;
public:
LinkSq(){
size_ = 0;
head = new Node;
head->Next = NULL;
}
void Insert(int a){
Node *pNode = new Node;
pNode->data = a;
pNode->Next = head->Next;
head->Next = pNode;
size_++;
}
void Display(){
Node *pCur = head->Next;
while(pCur != NULL){
cout << pCur->data << ' ';
pCur = pCur->Next;
}
}
};
int main(){
int a;
LinkSq LS;
while(1){
cin >> a;
if(a == -1){
break;
}
LS.Insert(a);
}
LS.Display();
return 0;
}```