-
Notifications
You must be signed in to change notification settings - Fork 2
/
books.h
159 lines (142 loc) · 3.28 KB
/
books.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#include <stdio.h>
#include <stdlib.h>
typedef struct books
{
int id;
char bookName[40];
int issued;
int available;
struct books *link;
} books;
// for initailse lib function
void createNode1(books **head1)
{
*head1 = (books *)malloc(sizeof(books));
if (*head1 == NULL)
printf("Cannot create BOOK\n");
}
// for inititalising lib finction
books * insertAtEnd1(books **head,int bookid)
{
books *newNode;
createNode1(&newNode);
if (newNode == NULL)
{
printf("Cannot insert the BOOK at end\n");
}
else
printf("BOOK inserted at end\n");
newNode->id=bookid;
newNode->link = NULL;
books *temp;
temp = *head;
if (temp == NULL)
{
*head = newNode;
}
else
{
while (temp->link != NULL)
{
temp = temp->link;
}
temp->link = newNode;
}
return newNode;
}
int isEmpty(books *head)
{
if (head == NULL)
return 1;
return 0;
}
void initialize_lib1(books ** ptr){
books *newNode;
newNode=insertAtEnd1(ptr,101);//Book 1
strcpy(newNode->bookName, "Mathematics");
newNode->available = 4;
newNode->issued = 0;
newNode=insertAtEnd1(ptr,102);// Book 2
strcpy(newNode->bookName, "Life");
newNode->available = 6;
newNode->issued = 0;
newNode=insertAtEnd1(ptr,103);// Book 3
strcpy(newNode->bookName, "Pschychology");
newNode->available = 9;
newNode->issued = 0;
newNode=insertAtEnd1(ptr,104);// Book 4
strcpy(newNode->bookName, "Basic_C");
newNode->available = 4;
newNode->issued = 0;
newNode=insertAtEnd1(ptr,105);// Book 5
strcpy(newNode->bookName, "Logic_design");
newNode->available = 8;
newNode->issued = 0;
}
void display(books *head)
{
if (isEmpty(head))
printf("The LIST is Empty\n");
else
{
printf("\nBOOKS DATA : \n");
while (head != NULL)
{
printf("\n----------- BOOK -----------\n");
printf("Book ID is : %d \n", head->id);
printf("Book name : %s \n", head->bookName);
printf("Available no. of books : %d \n", head->available);
printf("Books issued : %d", head->issued);
head = head->link;
printf("\n----------------------------\n");
}
printf("\n");
}
}
void input_data(books **head1)
{
printf("Enter Book ID : ");
scanf("%d", &((*head1)->id));
printf("Enter Book Name : ");
scanf("%s", &((*head1)->bookName));
printf("Enter available books : ");
scanf("%d", &((*head1)->available));
((*head1)->issued) = 0;
}
void createNode(books **head1)
{
*head1 = (books *)malloc(sizeof(books));
if (*head1 == NULL)
printf("Cannot create BOOK\n");
else
{
printf("BOOK created\n");
input_data(head1);
}
}
void insertAtEnd(books **head)
{
books *newNode;
createNode(&newNode);
if (newNode == NULL)
{
printf("Cannot insert the BOOK at end\n");
}
else
printf("Book inserted.\n\n");
newNode->link = NULL;
books *temp;
temp = *head;
if (temp == NULL)
{
*head = newNode;
}
else
{
while (temp->link != NULL)
{
temp = temp->link;
}
temp->link = newNode;
}
}