Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <malloc.h>
- typedef struct
- {
- char name[20];
- int age;
- float score;
- }Student;
- typedef struct NODE
- {
- Student Data;
- struct NODE* pNext;
- }NODE;
- typedef struct
- {
- NODE* pHead;
- NODE* pTail;
- }Tlist;
- void Create_Tlist(Tlist x)
- {
- x.pHead = x.pTail = NULL;
- }
- NODE* Create_NODE()
- {
- NODE* p = (NODE*)malloc(sizeof(NODE));
- if(p == NULL)
- {
- printf("Khong du bo nho");
- }
- p ->pNext = NULL;
- return p;
- }
- void Add_Last(Tlist *x, NODE *p)
- {
- if(x ->pHead == NULL)
- {
- x ->pHead = x ->pTail = p;
- }
- else
- {
- x ->pTail ->pNext = p;
- x ->pTail = p;
- }
- }
- void Input_NODE(NODE *p)
- {
- printf("Nhap ho ten: ");
- fflush(stdin);
- gets(p ->Data.name);
- printf("Nhap tuoi: ");
- scanf("%d", &p ->Data.age);
- fflush(stdin);
- printf("Nhap diem: ");
- scanf("%f", &p->Data.score);
- fflush(stdin);
- p->pNext = NULL;
- }
- void Input_Tlist(Tlist *x)
- {
- NODE* p = Create_NODE();
- Input_NODE(p);
- Add_Last(x, p);
- }
- void Output_NODE(NODE* p, int dem)
- {
- printf("\t|%5d|%25s|%5d|%5.2f|\n", dem, p ->Data.name, p ->Data.age, p->Data.score);
- }
- void Output_Tlist(Tlist x)
- {
- int dem = 1;
- NODE* y =x.pHead;
- printf("\t ___________________________________________\n");
- printf("\t|%5s|%25s|%5s|%5s|\n", "STT", "Ho va ten", "Tuoi", "Diem");
- printf("\t|%5s|%25s|%5s|%5s|\n", "-----", "-------------------------", "-----", "-----");
- while(y != NULL)
- {
- Output_NODE(y, dem);
- dem++;
- y = y ->pNext;
- }
- printf("\t|%5s|%25s|%5s|%5s|\n", "_____", "_________________________", "_____", "_____");
- }
- void Menu()
- {
- Tlist x;
- int n, i;
- Create_Tlist(x);
- printf("Nhap so luong sinh vien: ");
- scanf("%d", &n);
- for(i = 0; i < n; i++)
- {
- Input_Tlist(&x);
- }
- Output_Tlist(x);
- }
- int main()
- {
- Menu();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement