[C++练习]待Debug的单向链表
来源:互联网 发布:威科法律数据库 编辑:程序博客网 时间:2024/05/04 12:06
/*内存泄露*/
#include<iostream>using namespace std;class item{public:friend class List;item(){data=0; pre=0; }item(int x){data=x;pre=0;}private:int data;item *pre;};class List{public:List(){len=0;ed=0;}~List(){item *temp=ed->pre;while (temp){delete[] ed;ed=temp;temp=ed->pre;}}void Print(){item *temp=ed;while (ed){cout<<ed->data<<" ";ed=ed->pre;}cout<<endl;}int Length(){return len;}bool IsEmpty(){if (len) return false;return true;}void Add(int x){item *temp= new item(x);temp->pre=ed;ed=temp;len++;}void Del(){if ( !len ){cout<<"There is nothing to delete!"<<endl;return;}item *temp=ed->pre;delete[] ed;ed=temp;}private:int len;item *ed;};int main(){List list;int n;while (1){cin>>n;if (n==-1) break;list.Add(n);}cout<<list.Length()<<endl;list.Print();return 0;}
0 0
- [C++练习]待Debug的单向链表
- C语言练习01:单向链表的实现
- 数据结构练习--单向链表的实现
- C语言单向链表的创建、释放、插入、删除、翻转操作练习
- [算法练习]找到单向链表的中间节点
- C语言单向链表的实现
- 求助 C语言的单向链表
- C语言实现的单向链表
- 单向链表的C语言实现
- c语言的单向链表
- C++:操作单向链表的实现
- C语言单向链表的建立
- C语言单向链表的实现
- C语言单向链表的建立
- C语言单向链表的建立
- C语言单向链表的建立
- C语言单向链表的建立
- c语言单向链表的实现
- 初入职学习列表
- 卖糕的,又喝醉了
- Arrays.asList的使用及异常问题
- oracle临时表
- poj 2121 Inglish-Number Translator
- [C++练习]待Debug的单向链表
- Eclipse配置jboss运行ejb出现一个错误
- locale的设定及其LANG、LC_ALL、LANGUAGE环境变量的区别
- 办公室中打水故事
- LInux CUDA环境配置
- 提着高富帅的要求过穷矮搓的日子
- Struts2过滤器
- 关于基本最短路求解总结
- UVA 434 - Matty's Blocks(贪心)