C 언어 로 링크 를 작성 합 니 다.
체인 테이블
갖 춘 기본 기능:
1.헤드 링크 만 들 기
struct Node* Creatlist(){//
struct Node *headnode = (struct Node*)malloc(sizeof(struct Node));// ,
headnode->next = NULL;//
return headnode;
}
2.노드 만 들 기
struct Node* Creatnode(int num){// , ,
struct Node* newnode = (struct Node*)malloc(sizeof(struct Node));// ,
newnode->num = num;
newnode->next = NULL;//
return newnode;
}
3.노드 삽입
void Insetlist(struct Node* list, int num){//
struct Node* insetnode = Creatnode(num);
if (list != NULL){
insetnode->next = list->next;
list->next = insetnode;
}
else{
printf("
");
}
}
void Insetlists(struct Node* headnode, int n, int num){// n , , n , num
int i = 1;
struct Node *t = headnode;
while (i < n&& t!= NULL){
t = t->next;
i++;
}
if (t != NULL){
struct Node* insetnode = Creatnode(num);
insetnode->next = t->next;
t->next = insetnode;
}
else{
printf("
");
}
}
4.노드 수정
void Modifynode(struct Node* headnode, int n){// , , n
struct Node* list = headnode;
int i = 0;
while (i < n&&list != NULL){
list = list->next;
i++;
}
if (list != NULL){
printf("
");
int j = 0;
scanf("%d", &j);
list->num = j;
}
else{
printf("
");
}
}
5.노드 삭제두 개의 지침 을 정의 합 니 다.하 나 는 노드 를 삭제 하 는 이전 노드 를 가리 키 고 하 나 는 삭제 할 노드 를 가리 키 는 것 입 니 다.
void Deletnode(struct Node* headnode, int n){// n ,
int i = 1;
struct Node *strat = headnode;
struct Node *end = headnode->next;
while (i < n&&end != NULL){
strat = strat->next;
end = end->next;
i++;
}
if (end != NULL){
strat->next = end->next;
free(end);
}
else{
printf("
");
}
}
6.인쇄 노드
void Printnode(struct Node* headnode){//
struct Node* list = headnode;
while ((list->next) != NULL){
list = list->next;
printf("%d\t", list->num);
}
printf("
");
}
7.주 함수
int main(){
struct Node* list = Creatlist();
Insetlists(list, 1, 1);
Printnode(list);
int i = 0;
printf("
");
scanf("%d", &i);
Modifynode(list, i);
Printnode(list);
printf("
");
int n = 0;
scanf("%d", &n);
Deletnode(list, n);
Printnode(list);
system("pause");
return 0;
}
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
C 언어 구현 천둥 제거 게임 상세 정보먼저 작은 메뉴를 표시하고 게임을 할지 여부를 선택하십시오.사용자가 종료를 선택하면 프로그램 실행이 끝나고, 사용자가 게임을 선택하면 지뢰 제거 위치 좌표를 입력하라는 메시지가 표시됩니다.사용자가 입력한 좌표가 바둑...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.