Circular Doubly Linked List 双向循环链表 C++ 例子 (五)

2014-11-24 03:01:58 · 作者: · 浏览: 11
s


[cpp]
// CustomizedList.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "List.h"
#include

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{

List list;
int deleteva lue;
cout << "after initialize list" << endl;
cout << list;

cout << "try to delete with no element" << endl;
try{
list.Delete(0);
}catch(OutOfBounds){
cout << "delete error" << endl;
}

cout << "after call list.Insert(1,1)" << endl;
try{
list.Insert(1,1);
}catch(OutOfBounds){
cout << "insert error" << endl;
}
cout << list;

cout << "after call list.Insert(0,1)" << endl;
try{
list.Insert(0,1);
}catch(OutOfBounds){
cout << "insert error" << endl;
}
cout << list;

cout << "try to delete out range" << endl;
try{
list.Delete(2);
}catch(OutOfBounds){
cout << "delete error" << endl;
}
cout << list;

cout << "after call list.Push_Back(2) " << endl;
list.Push_Back(2);
cout << list;

cout << "delete position 0" << endl;
try{
list.Delete(0, deleteva lue);
}catch(OutOfBounds){
cout << "delete error" << endl;
}
cout << "delete value:" << deleteva lue << endl;
cout << list;

for(int i =0;i< 10; ++i){
list.Push_Back(i);
}
cout << list;

cout << "after call list.Clear()" << endl;
list.Clear();
cout << list;

int i;
cin >> i;
return 0;
}

// CustomizedList.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "List.h"
#include

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{

List list;
int deleteva lue;
cout << "after initialize list" << endl;
cout << list;

cout << "try to delete with no element" << endl;
try{
list.Delete(0);
}catch(OutOfBounds){
cout << "delete error" << endl;
}

cout << "after call list.Insert(1,1)" << endl;
try{
list.Insert(1,1);
}catch(OutOfBounds){
cout << "insert error" << endl;
}
cout << list;

cout << "after call list.Insert(0,1)" << endl;
try{
list.Insert(0,1);
}catch(OutOfBounds){
cout << "insert error" << endl;
}
cout << list;

cout << "try to delete out range" << endl;
try{
list.Delete(2);
}catch(OutOfBounds){
cout << "delete error" << endl;
}
cout << list;

cout << "after call list.Push_Back(2) " << endl;
list.Push_Back(2);
cout << list;

cout << "delete position 0" << endl;
try{
list.Delete(0, deleteva lue);
}catch(OutOfBounds){
cout << "delete error" << endl;
}
cout << "delete value:" << deleteva lue << endl;
cout << list;

for(int i =0;i< 10; ++i){
list.Push_Back(i);
}
cout << list;

cout << "after call list.Clear()" << endl;
list.Clear();
cout << list;

int i;
cin >> i;
return 0;
}

\