📄 chain.cpp
字号:
#include "chain.h"
void main(void)
{
try
{
Chain<int> L;
cout<<"Length= "<<L.Length()<<endl;
cout<<"IsEmpty= "<<L.IsEmpty()<<endl;
L.Insert(0,2);
L.Insert(1,6);
L.Insert(2,8);
L.Insert(3,4);
cout<<"List is "<<L<<endl;
//L.BinSort(8);
//L.BubbleSort();
//L.SelectionSort();
L.RankSort();
cout<<L<<endl;
int z;
L.Find(1,z);
cout<<L.Search(8)<<endl;
cout<<"First element is "<<z<<endl;
Chain<int> S=L;
L.Delete(1,z);
L.Append(19);
L.Append(10);
cout<<"Deleted element is "<<z<<endl;
cout<<"List is "<<L<<endl;
S.Reverse();
S.Append(5);
cout<<"Next list is "<<S<<endl;
int *x;
ChainIterator<int> c;
x=c.Initialize(L);
while (x)
{
cout<<*x<<' ';
x=c.Next();
}
cout<<endl<<endl;
Chain<int> C;
LinearList<int> L1(10);
L1.Insert(0,2).Insert(1,6).Insert(2,7).Insert(3,8).Insert(4,9);
cout << "List is " << L1 << endl;
C.FromList(L1);
cout << "The chain is " << C << endl;
L1.Delete(1,z).Delete(2,z);
cout << "List is " << L1 << endl;
C.ToList(L1);
cout << "List is " << L1 << endl << endl;
int n = 10, m = 5;
Chain<int> A1, B1, C1, C2, D1, E1;
// create A
for (int i = 0; i < n; i++)
A1.Insert(0, 2*(n - i));
// create B
for (i = 0; i < m; i++)
B1.Insert(0,2*(n - i) + 1);
cout << "First list is" << endl;
cout << A1 << endl;
cout << "Second list is" << endl;
cout << B1 << endl;
cout << "Merged list is" << endl;
cout << C1.Merge(A1,B1) << endl;
cout << "Melded list is" << endl;
cout << C2.Alternate(A1,B1) << endl;
C1.Split(D1, E1);
cout << "The first split list is" << endl;
cout << D1 << endl;
cout << "The second split list is" << endl;
cout << E1 << endl;
}
catch (...)
{
cerr << "An exception has occurred" << endl;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -