연결리스트를 이용한 큐로 데이터 관리 프로그램을 만드는 과제를 푸는데...

조회수 705회

이미지

'''
#include<stdio.h>
#include<stdlib.h>

typedef struct list{
    struct student * head;
    struct student * tail;
}list;

typedef struct student{
    char * name;
    int No;
    int Korean;
    int English;
    int Math;
    struct student * next;
}student;

void Insert(list * L,char * tname,int tNo,int tKorean,int tEnglish,int tMath);
void Delete(list * L);
void initialize(student * p);
void Display(student * p);
int main(void)
{
    list * ptr=malloc(sizeof(list));
    ptr->head=NULL;
    ptr->tail=NULL;
    char Name[100];
    int no;
    int korean;
    int english;
    int math;
    int input;
    while (1)
    {
        printf("\n1.Insert \n2.Delete\n 3.Display\n 4.Initialize\n");
        scanf("%d", &input);
        switch (input) {
            case 1:
                printf("Name: ");
                scanf(" %[^\n]",Name);
                printf("No: ");
                scanf(" %d",&no);
                printf("Korean: ");
                scanf(" %d",&korean);
                printf("English: ");
                scanf(" %d",&english);
                printf("Math: ");
                scanf(" %d",&math);
                Insert(ptr,Name,no,korean,english,math);
                break;
            case 2:
                Delete(ptr);
                break;
            case 3:
                Display(ptr);
                break;
            case 4:
                initialize(ptr);
                break;
            }
    }
    free(ptr);
}

void Insert(list * L,char * tname,int tNo,int tKorean,int tEnglish,int tMath)
{
    student * ptr=malloc(sizeof(student));
    ptr->name=tname;
    ptr->No=tNo;
    ptr->Korean=tKorean;
    ptr->English=tEnglish;
    ptr->Math=tMath;
    ptr->next=NULL;
    if(L->head==NULL && L->tail==NULL)
        L->head=L->tail=ptr;
    else
    {
        L->tail->next=ptr;
        L->tail=ptr;
    }
}


void Display(student * p)
{
    while((p)!=NULL)
    {
        printf("Name: %s\n",p->name);
        printf("No: %d\n",p->No);
        printf("Korean: %d\n",p->Korean);
        printf("English: %d\n",p->English);
        printf("Math: %d\n\n",p->Math);
        p=p->next;
    }
}
void initialize(student * p)
{
    p->next=NULL;
}
'''

이렇게 작성을 해보았는데, Delete 함수를 어떻게 작성해야하는지 모르겠어요 ㅠㅠ 도저히 감이 안오네요...Delete함수의 기능은 실행시 가장 먼저 입력한 학생의 신상정보를 Dequeue하고 출력을 하면 돼요 그리고 Initialize함수에서 모든 데이터를 삭제하는 코드가 저게 맞나요??

  • (•́ ✖ •̀)
    알 수 없는 사용자
  • 링크드리스트는 간단한 자료구조입니다. 일단 쉬운 예제로 학습을 진행하시기 바랍니다. 정영훈 2018.12.10 01:51

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)