www.gusucode.com > 两个VC++链表模板类-源码程序 > 两个VC++链表模板类-源码程序/code/双向链表/双向链表.cpp

    // 双向链表.cpp : Defines the entry point for the console application.
// Download by http://www.NewXing.com

#include "stdafx.h"
#include "qdlist.h"

int main(int argc, char* argv[])
{
	QDList<long> list;
	list.Append(100);
	list.Append(101);
	list.Append(110);
	list.Append(1000);
	list.Append(10008);
	list.Append(10009);	
	list.OutputList(cout);
	cout<<"\n链表长度等于:"<<list.GetLength()<<endl;

	/*cout<<"\n";
	list.RemoveAt(0);
	list.OutputList(cout);

	cout<<"\n";
	list.Append(1000090);	
	list.OutputList(cout);*/

	cout<<"\n";
	list.RemoveAt(1000);
	list.OutputList(cout);
	cout<<"\n链表长度等于:"<<list.GetLength()<<endl;

	cout<<"\n";
	list.RemoveAt(2);
	list.OutputList(cout);
	cout<<"\n链表长度等于:"<<list.GetLength()<<endl;

	cout<<"\n";
	list.RemoveAt(2);
	list.OutputList(cout);
	cout<<"\n链表长度等于:"<<list.GetLength()<<endl;

	cout<<"\n";
	list.RemoveAt(1);
	list.OutputList(cout);
	cout<<"\n链表长度等于:"<<list.GetLength()<<endl;

	cout<<"\n";
	list.Append(1);
	list.Append(12);
	list.Append(123);
	list.Append(1234);
	list.Append(12345);
	list.Append(123456);
	list.Append(1234567);
	list.OutputList(cout);
	cout<<"\n链表长度等于:"<<list.GetLength()<<endl;

	int Pos;
	list.Search(123,Pos);
	cout<<"\n 123位于:"<<Pos<<endl;

	list.Search(1234567,Pos);
	cout<<"\n 1234567位于:"<<Pos<<endl;

	list.Search(123456700,Pos);
	cout<<"\n 123456700位于:"<<Pos<<endl;

	list.Search(100,Pos);
	cout<<"\n 100位于:"<<Pos<<endl;

	list.Insert(0,90);
	list.OutputList(cout);
	cout<<"\n链表长度等于:"<<list.GetLength()<<endl;

	list.Insert(-1,89);
	list.OutputList(cout);
	cout<<"\n链表长度等于:"<<list.GetLength()<<endl;

	list.Insert(100,9999);
	list.OutputList(cout);
	cout<<"\n链表长度等于:"<<list.GetLength()<<endl;

	list.Insert(12,10000);
	list.OutputList(cout);
	cout<<"\n链表长度等于:"<<list.GetLength()<<endl;

	list.Insert(3,33);
	list.OutputList(cout);
	cout<<"\n链表长度等于:"<<list.GetLength()<<endl;

	list.Insert(8,88);
	list.OutputList(cout);
	cout<<"\n链表长度等于:"<<list.GetLength()<<endl;

	list.RemoveAll();
	list.Insert(0,1);
	list.Insert(1,2);
	list.Insert(2,3);
	list.Insert(3,4);
	list.Insert(4,5);
	list.Insert(5,6);
	list.Insert(6,7);
	list.OutputList(cout);
	cout<<"\n链表长度等于:"<<list.GetLength()<<endl;

	list.RemoveAt(0);
	list.OutputList(cout);
	cout<<"\n链表长度等于:"<<list.GetLength()<<endl;

	list.RemoveAt(-1);
	list.OutputList(cout);
	cout<<"\n链表长度等于:"<<list.GetLength()<<endl;

	list.RemoveAt(8);
	list.OutputList(cout);
	cout<<"\n链表长度等于:"<<list.GetLength()<<endl;

	list.RemoveAt(2);
	list.OutputList(cout);
	cout<<"\n链表长度等于:"<<list.GetLength()<<endl;

	list.RemoveAt(1);
	list.OutputList(cout);
	cout<<"\n链表长度等于:"<<list.GetLength()<<endl;

	list.RemoveAt(0);
	list.OutputList(cout);
	cout<<"\n链表长度等于:"<<list.GetLength()<<endl;

	list.RemoveAt(0);
	list.OutputList(cout);
	cout<<"\n链表长度等于:"<<list.GetLength()<<endl;

	list.RemoveAt(0);
	list.OutputList(cout);
	cout<<"\n链表长度等于:"<<list.GetLength()<<endl;

	printf("Hello World!\n");
	return 0;
}