Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <cstring>
- using namespace std;
- typedef struct Student {
- char *name;
- int grade;
- Student *next;
- } Student;
- void add (Student *&list, char *name, int grade) {
- Student *current;
- current = list;
- while (current->next != NULL) {
- current = current->next;
- }
- Student *new_student;
- new_student = new Student;
- strcpy(new_student->name, name);
- new_student->grade = grade;
- new_student->next = NULL;
- current->next = new_student;
- }
- void display (Student *list) {
- Student *current;
- current = list;
- while (current != NULL) {
- printf("%s %d\n", current->name, current->grade);
- current = current->next;
- }
- }
- int main(int argc, char* argv[]) {
- Student *list;
- list = new Student;
- int n;
- char name[21];
- float grade;
- scanf("%d", &n);
- scanf("%s %f", &list->name, &list->grade);
- list->next = NULL;
- for (int i = 1; i < n; i++) {
- scanf("%s %f", &name, &grade);
- add(list, name, grade);
- }
- display(list);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment