在我之前写的博客里,写过用C语言实现顺序表的博客(你们可以去看看哟),最近重新复习了C++,决定用C++重新实现一遍顺序表咦巩固我的基础。这里我用的是类来实现顺序表,下面是我代码的实现,简单易懂:
"test.cpp"
<strong><span style="font-size:18px;">#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
using namespace std;
#include "SeqList.h"
void Test1()
{
SeqList seq;
for (int i = 0;i < 5;i++)
{
seq.PushBack(i);
}
cout<<seq<<endl;
cout<<seq.Capacity()<<endl;
seq.PushFront(5);
seq.PushFront(6);
cout<<seq<<endl;
cout<<seq.Capacity()<<endl;
seq.PopBack();
seq.PopBack();
seq.PopBack();
cout<<seq<<endl;
seq.PopFront();
seq.PopFront();
cout<<seq<<endl;
}
void Test2()
{
SeqList seq;