feat: 添加 list 实现与测试,添加 stack 测试

This commit is contained in:
2024-07-28 14:53:08 +08:00
parent 8a80b3f8b9
commit d305d58e50
9 changed files with 186 additions and 43 deletions

View File

@@ -1,35 +1,42 @@
/**
* @file list.h
* @author clzhao98 <clzhao98@outlook.com>
* @brief
* @version 0.1
* @date 2024-07-28
*
* @copyright Copyright (c) 2024
*
*/
#ifndef __LIST__H__
#define __LIST__H__
#include <cstddef>
struct Node {
size_t data_p;
Node *next;
struct ListNode {
size_t val_;
ListNode *next;
ListNode(size_t val): val_(val), next(nullptr){} // 构造函数
};
class List {
public:
List();
~List();
void push_back(int data);
void push_front(int data);
void insert(int data, int index);
size_t front() const;
size_t back() const;
void push_back(size_t val);
void pop_back();
void pop_front();
void remove(int index);
void print();
int size();
bool empty();
void clear();
int front();
int back();
size_t size() const;
void dump() const;
private:
Node *head_;
Node *tail_;
int count_;
ListNode *head_;
ListNode *tail_;
size_t size_;
};
#endif //!__LIST__H__

35
include/stack.h Normal file
View File

@@ -0,0 +1,35 @@
/**
* @file stack.h
* @author clzhao98 <clzhao98@outlook.com>
* @brief
* @version 0.1
* @date 2024-07-28
*
* @copyright Copyright (c) 2024
*
*/
#ifndef __STACK__H__
#define __STACK__H__
/**
* @brief 先入先出
*
*/
#include <cstddef>
class Stack
{
private:
size_t capacity_;
public:
Stack();
~Stack();
void push(size_t val);
void pop();
size_t top();
bool empty();
size_t size();
};
#endif //!__STACK__H__