Filling + Printing Lists enabled
Added options for pushing, appending, inserting elements and for printing lists; Added MenuLib Dependency
This commit is contained in:
parent
3774feff77
commit
0c80e3372f
@ -145,6 +145,9 @@
|
||||
<ClCompile Include="main.c" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\MenuLib\MenuLib.vcxproj">
|
||||
<Project>{5ada9f67-f267-4ff6-ab61-e73c21f6ee36}</Project>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\Implementation\Implementation.vcxproj">
|
||||
<Project>{43c12dd0-611c-43ee-82f4-f25b33eed30b}</Project>
|
||||
</ProjectReference>
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "../Implementation/linked_list.h"
|
||||
#include "../../MenuLib/menu.h"
|
||||
|
||||
typedef struct {
|
||||
char* title;
|
||||
@ -40,12 +41,72 @@ void book_print(const void* data)
|
||||
printf("Book[title=%s,author=%s,year=%d]\n", book->title, book->author, book->year);
|
||||
}
|
||||
|
||||
void show_push(Node** list)
|
||||
{
|
||||
char title[101], author[101];
|
||||
int year;
|
||||
|
||||
printf("Enter title of Book: ");
|
||||
scanf_s(" %[^\n]s", title, 101);
|
||||
printf("Enter author of Book: ");
|
||||
scanf_s(" %[^\n]s", author, 101);
|
||||
printf("Enter year of Release: ");
|
||||
scanf_s(" %d", &year);
|
||||
|
||||
list_push(list, book_create(title, author, year));
|
||||
}
|
||||
|
||||
void show_append(Node** list)
|
||||
{
|
||||
char title[101], author[101];
|
||||
int year;
|
||||
|
||||
printf("Enter title of Book: ");
|
||||
scanf_s(" %[^\n]s", title, 101);
|
||||
printf("Enter author of Book: ");
|
||||
scanf_s(" %[^\n]s", author, 101);
|
||||
printf("Enter year of Release: ");
|
||||
scanf_s(" %d", &year);
|
||||
|
||||
list_append(list, book_create(title, author, year));
|
||||
}
|
||||
|
||||
void show_insert(Node** list)
|
||||
{
|
||||
char title[101], author[101];
|
||||
int year, index;
|
||||
|
||||
printf("Enter title of Book: ");
|
||||
scanf_s(" %[^\n]s", title, 101);
|
||||
printf("Enter author of Book: ");
|
||||
scanf_s(" %[^\n]s", author, 101);
|
||||
printf("Enter year of Release: ");
|
||||
scanf_s(" %d", &year);
|
||||
printf("Enter place after which book is inserted: ");
|
||||
scanf_s(" %d", &index);
|
||||
|
||||
list_insert(list_get(list, index), book_create(title, author, year));
|
||||
}
|
||||
|
||||
void show_print(Node** list)
|
||||
{
|
||||
list_print(*list, &book_print);
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
struct MenuItem items[] = {
|
||||
{"Push item", '1', (void*)&show_push, &list},
|
||||
{"Append item", '2', (void*)&show_append, &list},
|
||||
{"Insert item", '3', (void*)&show_insert, &list},
|
||||
{"Print item", '4', (void*)&show_print, &list},
|
||||
{"BLANK", NULL, NULL, NULL},
|
||||
{"Quit", 'q', (void*)&exit, NULL}
|
||||
};
|
||||
struct MenuPage pages[] = {
|
||||
{items, sizeof(items) / sizeof(struct MenuItem), "Linked List Demo", true, true, &SOLID}
|
||||
};
|
||||
show_menu(pages, sizeof(pages) / sizeof(struct MenuPage), true);
|
||||
}
|
Reference in New Issue
Block a user