Better way to go about it
This commit is contained in:
35
Q1.c
35
Q1.c
@@ -5,34 +5,21 @@
|
||||
typedef struct Student {
|
||||
int id;
|
||||
char name[30];
|
||||
double grade;
|
||||
double grades;
|
||||
struct Student *next;
|
||||
} Student;
|
||||
|
||||
typedef struct Node {
|
||||
Student student;
|
||||
struct Node* next;
|
||||
} Node;
|
||||
|
||||
Node* newNode(const int id, const char* name, const double grade) {
|
||||
Node* node = (Node*)malloc(sizeof(Node));
|
||||
node->student.id = id;
|
||||
strcpy(node->student.name, name);
|
||||
node->student.grade = grade;
|
||||
node->next = NULL;
|
||||
return node;
|
||||
// Create a student node
|
||||
Student *create_student(int id, char *name, double grades) {
|
||||
Student *student = (Student*)malloc(sizeof(Student));
|
||||
student->id = id;
|
||||
strcpy(student->name, name);
|
||||
student->grades = grades;
|
||||
student->next = NULL;
|
||||
return student;
|
||||
}
|
||||
|
||||
|
||||
void printStudents(Node* head) {
|
||||
Node* current = head;
|
||||
while (current != NULL) {
|
||||
printf("Student ID: %d\n", current->student.id);
|
||||
printf("Student Name: %s\n", current->student.name);
|
||||
printf("Student Grade: %f\n", current->student.grade);
|
||||
current = current->next;
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
void insert_student(Student *student) {}
|
||||
|
||||
int main(void) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user