게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
연결리스트 삭제 헬프 please~
게시물ID : computer_8704짧은주소 복사하기
작성자 : 씐난다
추천 : 0
조회수 : 296회
댓글수 : 3개
등록시간 : 2011/06/19 15:07:01
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef struct NodeRecord{
char name[10];
int kor,eng,math,tot;
double avg;
NodeRecord *next;
}Node;

Node *Make_List(Node *head,char name[],int kor,int eng,int math){
Node *new_node;
Node *p;
new_node=(Node*)malloc(sizeof(Node));
if(head==NULL){
strcpy(new_node->name,name);
new_node->kor=kor;
new_node->eng=eng;
new_node->math=math;
new_node->next=NULL;
head=new_node;
}else{
p=head;
while(p->next!=NULL) p=p->next;
strcpy(new_node->name,name);
new_node->kor=kor;
new_node->eng=eng;
new_node->math=math;
new_node->next=NULL;
p->next=new_node;
}
return head;
}

Node *Get_Sum_Avg(Node *head){
Node *p;
p=head;
while(p){
p->tot=p->kor+p->eng+p->math;
p->avg=p->tot/3.0;
p=p->next;
}
return head;
}

Node *Del_Node(Node *head,char name[]){   //여기 어떻게 해야됭미
Node *p;
p=head;
if(p->name==name){

}
return head;
}

void Display(Node *head){
static int count=0;
Node *p;
p=head;
if(count==0) printf("삭제전 리스트\n");
else printf("삭제후 리스트\n");
while(p){
printf("%s %d %d %d %d %0.1f\n",p->name,p->kor,p->eng,p->math,p->tot,p->avg);
p=p->next;
}
count++;
}

int main(void){
Node *list=NULL;
list=Make_List(list,"Kim",90,95,90);
list=Make_List(list,"Lee",95,95,95);
list=Make_List(list,"Park",90,90,90);
list=Get_Sum_Avg(list);
Display(list);
list=Del_Node(list,"Park");
Display(list);
}

Del_Node함수 어케해야할지 힌트좀 주세요 ㅜㅜ
if문 쓰고 전노드 후노드 만들어서 처음일때랑 중간에 삭제할때랑 구분해야되나요??
"Park"을 지워야되요
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호