附主函数:
#include<iostream>
#include"LinkedList.h"
using namespace std;
int main(){
LinkedList<int>list;
for(int i=0;i<10;i++){
int item;
cin>>item;
list.insertFront(item);
}
cout<<"输出链表:"<<endl;
list.reset();
while(!list.endOfList()){
cout<<list.data()<<" ";
list.next();
}
cout<<endl;
int key;
cout<<"输入删掉的元素:";
cin>>key;
list.reset();
while(!list.endOfList()){
if(list.data()==key)
list.deleteCurrent();
list.next();
}
cout<<"输出链表:"<<endl;
list.reset();
while(!list.endOfList()){
cout<<list.data()<<" ";
list.next();
}
cout<<endl;
list.clear();
list.reset();
while(!list.endOfList()){
cout<<list.data()<<" ";
list.next();
}
return 0;
}
全部评论
(0) 回帖