51 lines
1.0 KiB
C
51 lines
1.0 KiB
C
|
#include <stdlib.h>
|
||
|
#include <stdio.h>
|
||
|
#include <string.h>
|
||
|
|
||
|
#include "../Implementation/linked_list.h"
|
||
|
|
||
|
typedef struct {
|
||
|
char* title;
|
||
|
char* author;
|
||
|
int year;
|
||
|
} Book;
|
||
|
|
||
|
Book* book_create(const char* title, const char* author, int year)
|
||
|
{
|
||
|
// initialize book
|
||
|
Book* book = calloc(1, sizeof(Book));
|
||
|
if (!book)
|
||
|
{
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
// initialize title and author
|
||
|
book->title = calloc(strlen(title), sizeof(char));
|
||
|
book->author = calloc(strlen(author), sizeof(char));
|
||
|
if (!book->title || !book->author)
|
||
|
{
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
strcpy(book->title, title);
|
||
|
strcpy(book->author, author);
|
||
|
book->year = year;
|
||
|
|
||
|
return book;
|
||
|
}
|
||
|
|
||
|
void book_print(const void* data)
|
||
|
{
|
||
|
const Book* book = (Book*)data;
|
||
|
printf("Book[title=%s,author=%s,year=%d]\n", book->title, book->author, book->year);
|
||
|
}
|
||
|
|
||
|
void main(void)
|
||
|
{
|
||
|
Node* list = NULL;
|
||
|
list_push(&list, book_create("Java ist auch eine Insel", "Christian Ullenboom", 2011));
|
||
|
list_push(&list, book_create("C/C++", "Kaiser, Guddat", 2014));
|
||
|
list_print(list, &book_print);
|
||
|
list_remove(list_get(list, 1));
|
||
|
list_print(list, &book_print);
|
||
|
}
|