/
rgd045
/
crypto-algorithms
Обзор
Документация
Войти
/
rgd045
/
crypto-algorithms
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
test/struct/test_dlist.c
58 строк
1 KB
Aleksander Alekseev
Change project structure
26 сен 2016, 18:02
26 сен 2016, 18:02
0b0596c
Код
Авторство
О чём код?
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> #include "struct/ilist.h" typedef struct { dlist_node node; char data[128]; } ListItemData; typedef ListItemData *ListItem; int main() { dlist_iter iter; ListItemData item1, item2, item3; ListItem tmp; char temp_buff[512]; dlist_head head; dlist_init(&head); assert(dlist_is_empty(&head)); strcpy(item1.data, "first item"); strcpy(item2.data, "second item"); strcpy(item3.data, "third item"); dlist_push_tail(&head, (dlist_node*) &item1); assert(!dlist_is_empty(&head)); dlist_push_tail(&head, (dlist_node*) &item2); dlist_push_tail(&head, (dlist_node*) &item3); temp_buff[0] = 0; dlist_foreach(iter, &head) { tmp = (ListItem) iter.cur; strcat(temp_buff, tmp->data); strcat(temp_buff, ","); } assert(strcmp(temp_buff, "first item,second item,third item,") == 0); tmp = (ListItem) dlist_pop_tail_node(&head); assert(strcmp(tmp->data, "third item") == 0); temp_buff[0] = 0; dlist_foreach(iter, &head) { tmp = (ListItem) iter.cur; strcat(temp_buff, tmp->data); strcat(temp_buff, ","); } assert(strcmp(temp_buff, "first item,second item,") == 0); return 0; }