c++ / day06

1. 利用模板类完成顺序表(两天时间,今天至少写出大致框架)

代码

//implement template in sqlist
#include 
#include 

#define MAXSIZE 100

using namespace std;

template 
class Sqlist
{
    unsigned int len = 0;
    T *ptr_data=NULL;

public:
    Sqlist():ptr_data(new T [MAXSIZE])
    {
         cout << "Sqlist init" <
int Sqlist::init()
{
    if (NULL == ptr_data) //why ther is a warning?
    {
        cout << "ptr_data is NULL" <
int Sqlist::push(T element)
{
    //is full
    if(len == MAXSIZE)
    {
        cout << "sqlist is full" <
T Sqlist::at(unsigned index)
{
    if(index < 0 || len > MAXSIZE)
    {
        cout << "index is out of range" < list;

    for(int i=0; i<10; i++)
    {
        list.push(i*i);
    }

    for(unsigned int i=0; i<10; i++)
    {
        cout << "list.at(" << i << ")" <

运行结果

c++ / day06_第1张图片

2. 整理思维导图

c++ / day06_第2张图片

你可能感兴趣的:(c++,开发语言)