-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedListAssignment5.c
More file actions
103 lines (86 loc) · 2.27 KB
/
LinkedListAssignment5.c
File metadata and controls
103 lines (86 loc) · 2.27 KB
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
#include <stdio.h>
#include <string.h>
#define MAX 50
typedef char String[100];
typedef struct {
char LName[16];
char FName[24];
char Mi;
} Name;
typedef struct {
Name name;
unsigned int ID;
char Course[8];
int Year;
} Student;
typedef struct {
Student students[MAX];
int count;
} List;
void insert(Student x, int p, List *L){
if(L->count<MAX && (p<=L->count && p>=0)){
if(p!=L->count){
int i;
for(i=L->count; i>p; i--){
L->students[i] = L->students[i-1];
}
}
L->students[p] = x;
L->count++;
} else {
printf("Insert position is out of bounds or list is full.\n");
}
}
void delete(int p, List *L){
if(p<L->count && p>=0){
if(p!=L->count-1){
int i;
for(i=p; i<L->count-1; i++){
L->students[i] = L->students[i+1];
}
}
L->count--;
}
}
int locate(char x[], List L){
int i;
for(i=0; i<L.count && strcmp(x, L.students[i].name.LName) != 0; i++){}
return (i<L.count) ? i : -1; // -1 is a dummy value
}
Student retrieve (int p, List L){
Student student = {{"XXXX", "XXXX", 'X'}, 0, "XXXX", 0}; // Dummy value
if(p<L.count && p>=0){
student = L.students[p];
}
return student;
}
void makenull(List *L){
L->count = 0;
}
void printList(List L){
int i;
char nameFormat[48];
for(i=0; i<L.count; i++){
sprintf(nameFormat, "%s, %s %c.", L.students[i].name.LName, L.students[i].name.FName, L.students[i].name.Mi);
printf("- %s - %u, %s, %d\n", nameFormat, L.students[i].ID, L.students[i].Course, L.students[i].Year);
}
}
void printStud(Student stud){
char nameFormat[48];
sprintf(nameFormat, "%s, %s %c.", stud.name.LName, stud.name.FName, stud.name.Mi);
printf("- %s - %u, %s, %d\n", nameFormat, stud.ID, stud.Course, stud.Year);
}
int main(){
List myList = {
{
{{"Dela Cruz", "Juan", 'J'}, 21700005, "BSCS", 3},
{{"Garcia", "Juanito", 'E'}, 21700006, "BSCS", 3}
},
2
};
Student insertThis = {{"Abrams", "John", 'M'}, 21700007, "BSIT", 2};
printf("the value of pos %d is: ", 1);
printStud(retrieve(1, myList));
printList(myList);
return 0;
}