mirror of
https://gitee.com/apaki/unicstl.git
synced 2025-07-03 23:56:54 +08:00
添加注释
This commit is contained in:
parent
0a69ed1339
commit
a36bfd7507
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -12,6 +12,7 @@
|
|||||||
"list.h": "c",
|
"list.h": "c",
|
||||||
"stdio.h": "c",
|
"stdio.h": "c",
|
||||||
"tree.h": "c",
|
"tree.h": "c",
|
||||||
"deque.h": "c"
|
"deque.h": "c",
|
||||||
|
"config.h": "c"
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,6 +1,6 @@
|
|||||||
|
|
||||||
#ifndef _DEMO_H_
|
#ifndef _COMMON_H_
|
||||||
#define _DEMO_H_
|
#define _COMMON_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@ -9,9 +9,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
#include "config.h"
|
|
||||||
|
|
||||||
|
|
||||||
#if RBTREE == 1
|
#if RBTREE == 1
|
||||||
#include "rbtree.h"
|
#include "rbtree.h"
|
||||||
typedef prbtree_node_t stack_data_t;
|
typedef prbtree_node_t stack_data_t;
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
|
|
||||||
#ifndef _CONFIG_H_
|
|
||||||
#define _CONFIG_H_
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
|
|
||||||
// optional
|
|
||||||
#define RBTREE 0
|
|
||||||
#define AVLTREE 0
|
|
||||||
#define RAVLTREE 0 // avl tree by recursion
|
|
||||||
#define QUEUE 0
|
|
||||||
#define STACK 1
|
|
||||||
#define LIST 1
|
|
||||||
|
|
||||||
|
|
||||||
// --------------------------------------------------
|
|
||||||
#if RBTREE == 1 && AVLTREE == 1
|
|
||||||
#error "Rbtree and avltree cannot coexist"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if RAVLTREE == 1 && AVLTREE == 1
|
|
||||||
#error "Recursive avltree and avltree cannot coexist"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // _CONFIG_H_
|
|
||||||
|
|
@ -1,8 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* @file deque.h
|
||||||
|
* @author wenjf (Orig5826@163.com)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2024-06-23
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
#ifndef _DEQUE_H_
|
#ifndef _DEQUE_H_
|
||||||
#define _DEQUE_H_
|
#define _DEQUE_H_
|
||||||
|
|
||||||
#include "unicstl.h"
|
#include "common.h"
|
||||||
|
|
||||||
struct _deque_node
|
struct _deque_node
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* @file list.h
|
||||||
|
* @author wenjf (Orig5826@163.com)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2024-06-23
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
#ifndef _LIST_H_
|
#ifndef _LIST_H_
|
||||||
#define _LIST_H_
|
#define _LIST_H_
|
||||||
|
|
||||||
#include "unicstl.h"
|
#include "common.h"
|
||||||
|
|
||||||
struct _list
|
struct _list
|
||||||
{
|
{
|
||||||
|
@ -13,38 +13,6 @@
|
|||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
#if QUEUE == 1
|
|
||||||
// typedef int queue_data_t;
|
|
||||||
|
|
||||||
// node of queue
|
|
||||||
typedef struct _queue_node_t
|
|
||||||
{
|
|
||||||
queue_data_t data;
|
|
||||||
struct _queue_node_t * next;
|
|
||||||
} queue_node_t, *pqueue_node_t;
|
|
||||||
|
|
||||||
// queue
|
|
||||||
typedef struct _queue_t
|
|
||||||
{
|
|
||||||
struct _queue_node_t * front;
|
|
||||||
struct _queue_node_t * rear;
|
|
||||||
uint32_t size;
|
|
||||||
}queue_t,*pqueue_t;
|
|
||||||
|
|
||||||
|
|
||||||
bool queue_init(pqueue_t * head);
|
|
||||||
void queue_destroy(pqueue_t * head);
|
|
||||||
bool queue_empty(pqueue_t head);
|
|
||||||
void queue_clear(pqueue_t head);
|
|
||||||
uint32_t queue_get_size(pqueue_t head);
|
|
||||||
|
|
||||||
bool queue_in(pqueue_t head, queue_data_t data);
|
|
||||||
void queue_out(pqueue_t head, queue_data_t *data);
|
|
||||||
bool queue_get_front(pqueue_t head, queue_data_t *data);
|
|
||||||
bool queue_get_rear(pqueue_t head, queue_data_t *data);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct _queue_node
|
struct _queue_node
|
||||||
{
|
{
|
||||||
void *obj;
|
void *obj;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#ifndef _RBTREE_H_
|
#ifndef _RBTREE_H_
|
||||||
#define _RBTREE_H_
|
#define _RBTREE_H_
|
||||||
|
|
||||||
#include "config.h"
|
#include "common.h"
|
||||||
|
|
||||||
#if RBTREE == 1
|
#if RBTREE == 1
|
||||||
typedef int rbtree_data_t;
|
typedef int rbtree_data_t;
|
||||||
|
@ -1,3 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* @file stack.h
|
||||||
|
* @author wenjf (Orig5826@163.com)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2024-06-23
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
#ifndef _STACK_H_
|
#ifndef _STACK_H_
|
||||||
#define _STACK_H_
|
#define _STACK_H_
|
||||||
|
|
||||||
|
@ -1,3 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* @file tree.h
|
||||||
|
* @author wenjf (Orig5826@163.com)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2024-06-23
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
#ifndef _TREE_H_
|
#ifndef _TREE_H_
|
||||||
#define _TREE_H_
|
#define _TREE_H_
|
||||||
|
|
||||||
@ -77,7 +87,7 @@ struct _tree_node
|
|||||||
uint32_t color;
|
uint32_t color;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
typedef struct _tree_node * tree_node_t;
|
typedef struct _tree_node* tree_node_t;
|
||||||
|
|
||||||
struct _tree
|
struct _tree
|
||||||
{
|
{
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* @file unicstl.h
|
||||||
|
* @author wenjf (Orig5826@163.com)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2024-06-23
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
#ifndef _DEMO_H_
|
#ifndef _DEMO_H_
|
||||||
#define _DEMO_H_
|
#define _DEMO_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
#include "stack.h"
|
#include "stack.h"
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
|
11
src/deque.c
11
src/deque.c
@ -1,4 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* @file deque.c
|
||||||
|
* @author wenjf (Orig5826@163.com)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2024-06-23
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
#include "deque.h"
|
#include "deque.h"
|
||||||
|
|
||||||
bool deque_push_back(struct _deque* self, void* obj)
|
bool deque_push_back(struct _deque* self, void* obj)
|
||||||
|
11
src/list.c
11
src/list.c
@ -1,4 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* @file list.c
|
||||||
|
* @author wenjf (Orig5826@163.com)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2024-06-23
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
|
||||||
bool list_append(struct _list* self, void* obj)
|
bool list_append(struct _list* self, void* obj)
|
||||||
|
148
src/queue.c
148
src/queue.c
@ -1,142 +1,14 @@
|
|||||||
|
/**
|
||||||
|
* @file queue.c
|
||||||
|
* @author wenjf (Orig5826@163.com)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2024-06-23
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
#if QUEUE == 1
|
|
||||||
|
|
||||||
bool queue_init(pqueue_t * head)
|
|
||||||
{
|
|
||||||
*head = (pqueue_t)malloc(sizeof(queue_t));
|
|
||||||
ifqueue_head == NULL)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
queue_head)->front = NULL;
|
|
||||||
queue_head)->rear = NULL;
|
|
||||||
queue_head)->size = 0;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void queue_destroy(pqueue_t * head)
|
|
||||||
{
|
|
||||||
ifqueue_head != NULL)
|
|
||||||
{
|
|
||||||
queue_clearqueue_head);
|
|
||||||
freequeue_head);
|
|
||||||
*head = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool queue_empty(pqueue_t head)
|
|
||||||
{
|
|
||||||
return (head == NULL || head->front == NULL || head->rear == NULL) ? true : false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void queue_clear(pqueue_t head)
|
|
||||||
{
|
|
||||||
pqueue_node_t front_item;
|
|
||||||
if(head != NULL)
|
|
||||||
{
|
|
||||||
front_item = head->front;
|
|
||||||
while(head->front != NULL)
|
|
||||||
{
|
|
||||||
head->front = front_item->next;
|
|
||||||
free(front_item);
|
|
||||||
front_item = head->front;
|
|
||||||
}
|
|
||||||
head->rear = head->front;
|
|
||||||
head->size = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t queue_get_size(pqueue_t head)
|
|
||||||
{
|
|
||||||
return head->size;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool queue_in(pqueue_t head, queue_data_t data)
|
|
||||||
{
|
|
||||||
pqueue_node_t new_item;
|
|
||||||
if(head == NULL)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
new_item = (pqueue_node_t)malloc(sizeof(queue_node_t));
|
|
||||||
if(new_item == NULL)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
new_item->data = data;
|
|
||||||
new_item->next = NULL;
|
|
||||||
if(head->front == NULL)
|
|
||||||
{
|
|
||||||
head->front = new_item;
|
|
||||||
}
|
|
||||||
// insert from tail
|
|
||||||
if(head->rear != NULL)
|
|
||||||
{
|
|
||||||
head->rear->next = new_item;
|
|
||||||
}
|
|
||||||
head->rear = new_item;
|
|
||||||
|
|
||||||
if (head->size < _UI32_MAX)
|
|
||||||
{
|
|
||||||
head->size++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void queue_out(pqueue_t head, queue_data_t *data)
|
|
||||||
{
|
|
||||||
pqueue_node_t front_item;
|
|
||||||
if(!queue_empty(head))
|
|
||||||
{
|
|
||||||
front_item = head->front;
|
|
||||||
*data = front_item->data;
|
|
||||||
|
|
||||||
// free the front item
|
|
||||||
head->front = front_item->next;
|
|
||||||
free(front_item);
|
|
||||||
front_item = NULL;
|
|
||||||
if (queue_get_size(head) == 1)
|
|
||||||
{
|
|
||||||
head->rear = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (head > 0)
|
|
||||||
{
|
|
||||||
head->size--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool queue_get_front(pqueue_t head, queue_data_t *data)
|
|
||||||
{
|
|
||||||
if(!queue_empty(head))
|
|
||||||
{
|
|
||||||
*data = head->front->data;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool queue_get_rear(pqueue_t head, queue_data_t *data)
|
|
||||||
{
|
|
||||||
if(!queue_empty(head))
|
|
||||||
{
|
|
||||||
*data = head->rear->data;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
bool queue_push(struct _queue* self, void* obj)
|
bool queue_push(struct _queue* self, void* obj)
|
||||||
{
|
{
|
||||||
|
11
src/stack.c
11
src/stack.c
@ -1,4 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* @file stack.c
|
||||||
|
* @author wenjf (Orig5826@163.com)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2024-06-23
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
#include "stack.h"
|
#include "stack.h"
|
||||||
|
|
||||||
static uint32_t stack_capacity(struct _stack* self)
|
static uint32_t stack_capacity(struct _stack* self)
|
||||||
|
15
src/tree.c
15
src/tree.c
@ -1,4 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* @file tree.c
|
||||||
|
* @author wenjf (Orig5826@163.com)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2024-06-23
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
#include "tree.h"
|
#include "tree.h"
|
||||||
|
|
||||||
#if RAVLTREE == 1
|
#if RAVLTREE == 1
|
||||||
@ -1393,7 +1402,7 @@ static bool tree_rebalance(ptree_t head, ptree_node_t tree)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static tree_node_t * tree_node_new(struct _tree* self, void* obj)
|
static tree_node_t tree_node_new(struct _tree* self, void* obj)
|
||||||
{
|
{
|
||||||
void * obj_new = malloc(self->_obj_size);
|
void * obj_new = malloc(self->_obj_size);
|
||||||
if (obj_new == NULL)
|
if (obj_new == NULL)
|
||||||
@ -1402,7 +1411,7 @@ static tree_node_t * tree_node_new(struct _tree* self, void* obj)
|
|||||||
}
|
}
|
||||||
memmove(obj_new, obj, self->_obj_size);
|
memmove(obj_new, obj, self->_obj_size);
|
||||||
|
|
||||||
struct _tree_node* node_new = (struct _queue_node*)malloc(sizeof(struct _tree_node));
|
struct _tree_node* node_new = (struct _tree_node*)malloc(sizeof(struct _tree_node));
|
||||||
if(node_new == NULL)
|
if(node_new == NULL)
|
||||||
{
|
{
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -1,2 +1,11 @@
|
|||||||
|
/**
|
||||||
|
* @file unicstl.c
|
||||||
|
* @author wenjf (Orig5826@163.com)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2024-06-23
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
#include "unicstl.h"
|
#include "unicstl.h"
|
||||||
|
@ -27,10 +27,10 @@ int main()
|
|||||||
printf("----- unicstl test -----\n");
|
printf("----- unicstl test -----\n");
|
||||||
// while (1)
|
// while (1)
|
||||||
{
|
{
|
||||||
list_test();
|
test_list();
|
||||||
test_stack();
|
test_stack();
|
||||||
deque_test();
|
test_deque();
|
||||||
queue_test();
|
test_queue();
|
||||||
|
|
||||||
// tree_test();
|
// tree_test();
|
||||||
// rbtree_test();
|
// rbtree_test();
|
||||||
|
@ -26,11 +26,11 @@ void print_str(void* obj);
|
|||||||
* @brief test function
|
* @brief test function
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void list_test(void);
|
void test_list(void);
|
||||||
void test_stack(void);
|
void test_stack(void);
|
||||||
void deque_test(void);
|
void test_deque(void);
|
||||||
|
|
||||||
void queue_test(void);
|
void test_queue(void);
|
||||||
void tree_test(void);
|
void tree_test(void);
|
||||||
void rbtree_test(void);
|
void rbtree_test(void);
|
||||||
|
|
||||||
|
@ -1,7 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* @file test_deque.c
|
||||||
|
* @author wenjf (Orig5826@163.com)
|
||||||
|
* @brief
|
||||||
|
* @version 0.1
|
||||||
|
* @date 2024-06-23
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2024
|
||||||
|
*
|
||||||
|
*/
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
static void deque_test_num(void)
|
static void test_deque_num(void)
|
||||||
{
|
{
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
int data[] = { 1,2,3,4,5,6,7,8,9,10 };
|
int data[] = { 1,2,3,4,5,6,7,8,9,10 };
|
||||||
@ -12,7 +21,7 @@ static void deque_test_num(void)
|
|||||||
deque_init(&dq, sizeof(int));
|
deque_init(&dq, sizeof(int));
|
||||||
dq.print_obj = print_num;
|
dq.print_obj = print_num;
|
||||||
|
|
||||||
printf("\n\n----- deque_test_num -----\n");
|
printf("\n\n----- test_deque_num -----\n");
|
||||||
|
|
||||||
printf("----- after push_back -----\n");
|
printf("----- after push_back -----\n");
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
@ -169,7 +178,7 @@ static void deque_test_num(void)
|
|||||||
dq.destory(&dq);
|
dq.destory(&dq);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void deque_test_struct(void)
|
static void test_deque_struct(void)
|
||||||
{
|
{
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
struct _student data[] = {
|
struct _student data[] = {
|
||||||
@ -184,7 +193,7 @@ static void deque_test_struct(void)
|
|||||||
deque_init(&dq, sizeof(struct _student));
|
deque_init(&dq, sizeof(struct _student));
|
||||||
dq.print_obj = print_struct;
|
dq.print_obj = print_struct;
|
||||||
|
|
||||||
printf("\n\n----- deque_test_struct -----\n");
|
printf("\n\n----- test_deque_struct -----\n");
|
||||||
|
|
||||||
printf("----- after push_back -----\n");
|
printf("----- after push_back -----\n");
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
@ -343,8 +352,8 @@ static void deque_test_struct(void)
|
|||||||
dq.destory(&dq);
|
dq.destory(&dq);
|
||||||
}
|
}
|
||||||
|
|
||||||
void deque_test(void)
|
void test_deque(void)
|
||||||
{
|
{
|
||||||
deque_test_num();
|
test_deque_num();
|
||||||
deque_test_struct();
|
test_deque_struct();
|
||||||
}
|
}
|
||||||
|
@ -291,7 +291,7 @@ static void test_list_struct(void)
|
|||||||
list.destory(&list);
|
list.destory(&list);
|
||||||
}
|
}
|
||||||
|
|
||||||
void list_test(void)
|
void test_list(void)
|
||||||
{
|
{
|
||||||
test_list_num();
|
test_list_num();
|
||||||
test_list_struct();
|
test_list_struct();
|
||||||
|
@ -1,154 +1,7 @@
|
|||||||
|
|
||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
#if QUEUE_TEST == 1
|
static void test_queue_num(void)
|
||||||
|
|
||||||
void queue_test(void)
|
|
||||||
{
|
|
||||||
int32_t i = 0;
|
|
||||||
uint32_t size;
|
|
||||||
queue_data_t dat[10] = {0,1,2,3,4,5,6,7,8,9};
|
|
||||||
queue_data_t tmp;
|
|
||||||
pqueue_t que;
|
|
||||||
|
|
||||||
if(!queue_init(&que))
|
|
||||||
{
|
|
||||||
printf("failure -> queue_init\n");
|
|
||||||
}
|
|
||||||
printf("success -> queue_init\n");
|
|
||||||
|
|
||||||
for(i = 0; i < 10; i++)
|
|
||||||
{
|
|
||||||
if(!queue_in(que,dat[i]))
|
|
||||||
{
|
|
||||||
printf("failure -> queue_in\n");
|
|
||||||
}
|
|
||||||
if(!queue_get_front(que,&tmp))
|
|
||||||
{
|
|
||||||
printf("failure -> queue_get_front\t");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf(" front = %d",tmp);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!queue_get_rear(que,&tmp))
|
|
||||||
{
|
|
||||||
printf("failure -> queue_get_rear\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf(" rear = %d\n",tmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
printf("success -> queue_in\n");
|
|
||||||
if(!queue_empty(que))
|
|
||||||
{
|
|
||||||
printf("success -> queue is not empty!\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("failure -> queue is not empty!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
size = queue_get_size(que);
|
|
||||||
if (size != 10)
|
|
||||||
{
|
|
||||||
printf("failure -> the size of queue is : %d\n", size);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("success -> the size of queue is : %d\n", size);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("success -> queue_empty\n");
|
|
||||||
for(i = 0; i < 10; i++)
|
|
||||||
{
|
|
||||||
if(!queue_get_front(que,&tmp))
|
|
||||||
{
|
|
||||||
printf("failure -> queue_get_front\t");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf(" front = %d\t",tmp);
|
|
||||||
}
|
|
||||||
if(!queue_get_rear(que,&tmp))
|
|
||||||
{
|
|
||||||
printf("failure -> queue_get_rear\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf(" rear = %d\n",tmp);
|
|
||||||
}
|
|
||||||
queue_out(que,&tmp);
|
|
||||||
}
|
|
||||||
printf("success -> queue_out\n");
|
|
||||||
if(queue_empty(que))
|
|
||||||
{
|
|
||||||
printf("success -> queue is empty!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
size = queue_get_size(que);
|
|
||||||
if (size != 0)
|
|
||||||
{
|
|
||||||
printf("failure -> the size of queue is : %d\n", size);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("success -> the size of queue is : %d\n", size);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(i = 0; i < 5; i++)
|
|
||||||
{
|
|
||||||
if(!queue_in(que,dat[i]))
|
|
||||||
{
|
|
||||||
printf("failure -> queue_in\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!queue_empty(que))
|
|
||||||
{
|
|
||||||
printf("success -> queue is not empty!\n");
|
|
||||||
queue_clear(que);
|
|
||||||
printf("success -> queue_clear\n");
|
|
||||||
|
|
||||||
if(queue_empty(que))
|
|
||||||
{
|
|
||||||
printf("success -> queue is empty!\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("failure -> queue is not empty!\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
queue_destroy(&que);
|
|
||||||
printf("success -> queue_destroy\n");
|
|
||||||
|
|
||||||
if(!queue_in(que,dat[0]))
|
|
||||||
{
|
|
||||||
printf("success -> If que if NULL, queue_in return failure\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
queue_out(que,&tmp);
|
|
||||||
printf("success -> queue_out invalid!\n");
|
|
||||||
|
|
||||||
if(queue_empty(que))
|
|
||||||
{
|
|
||||||
printf("success -> If que is NULL, queue_empty alse return true!\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
printf("failure -> Que is NULL, but queue_empty return true!\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
printf("----------------------------------------\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
|
|
||||||
static void queue_test_num(void)
|
|
||||||
{
|
{
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
int data[] = { 1,2,3,4,5,6,7,8,9,10 };
|
int data[] = { 1,2,3,4,5,6,7,8,9,10 };
|
||||||
@ -159,7 +12,7 @@ static void queue_test_num(void)
|
|||||||
queue_init(&queue, sizeof(int));
|
queue_init(&queue, sizeof(int));
|
||||||
queue.print_obj = print_num;
|
queue.print_obj = print_num;
|
||||||
|
|
||||||
printf("\n\n----- queue_test_num -----\n");
|
printf("\n\n----- test_queue_num -----\n");
|
||||||
|
|
||||||
printf("----- after push-----\n");
|
printf("----- after push-----\n");
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
@ -233,7 +86,7 @@ static void queue_test_num(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void queue_test_char(void)
|
static void test_queue_char(void)
|
||||||
{
|
{
|
||||||
uint32_t i = 0;
|
uint32_t i = 0;
|
||||||
char data[] = "abcdefghijk";
|
char data[] = "abcdefghijk";
|
||||||
@ -245,7 +98,7 @@ static void queue_test_char(void)
|
|||||||
queue_init2(&queue, sizeof(char), 10);
|
queue_init2(&queue, sizeof(char), 10);
|
||||||
queue.print_obj = print_char;
|
queue.print_obj = print_char;
|
||||||
|
|
||||||
printf("\n\n----- queue_test_char -----\n");
|
printf("\n\n----- test_queue_char -----\n");
|
||||||
|
|
||||||
printf("----- after push-----\n");
|
printf("----- after push-----\n");
|
||||||
for (i = 0; i < len; i++)
|
for (i = 0; i < len; i++)
|
||||||
@ -328,11 +181,8 @@ static void queue_test_char(void)
|
|||||||
queue.destory(&queue);
|
queue.destory(&queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
void queue_test(void)
|
void test_queue(void)
|
||||||
{
|
{
|
||||||
// queue_test_num();
|
test_queue_num();
|
||||||
queue_test_char();
|
test_queue_char();
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user