-2
링크 된 목록의 기본 삽입 및 표시 작업을위한 코드이지만 삽입 함수 프로그램에 대한 인수 키와 정보를 입력 한 후에 진행하지 마십시오. 그리고 5 정보로 머리가 가리키는 노드가 만들어 져야하고 show가 하나의 요소가있는 내 연결된 목록이라고 불리는 경우 표시되어야하지만 일어나지는 않습니다. 삽입 및 쇼 기능에 문제가 있거나 무엇을해야합니까?연결된 목록 코드의 삽입 작업이 작동하지 않습니다.
#include <stdio.h>
#include <stdlib.h>
static struct node{
int key, info;
struct node *next;
};
static struct node *head, *z;
initialize()
{
head = (struct node*)malloc(sizeof *head);
z = (struct node*)malloc(sizeof *z);
head->next = z;
z->next = z;
z->key = -1;
}
insert(int n, int info)
{
struct node *t, *x;
t = head;
while (t->next != z) {
t = t->next;
}
x = (struct node *)malloc (sizeof *x);
x->key = n;
x->next = t->next;
t->next = x;
x->info = info;
}
show()
{
struct node *t = head;
while (t->next != z) {
t = t->next;
printf("%d\t%d\n", t->key, t->info);
}
}
main()
{
initialize();
int i, j;
printf("enter the number and info\n");
scanf("%d%d", &i, &j); // i is key and j is info
insert(i, j); // passing arguments to insert function
show();
}
_progamme do not proceed? 당신은 절대로'show()'를 호출하지 않는다는 것을 알고 있습니까? –
코드에'stdlib.h'를 포함 시키십시오. – user1336087
가능한 경고를 보려면'-Wall' 옵션을 사용하여 코드를 컴파일하십시오. 그리고'insert()'를 호출 한 후 출력을보기 위해'show()'를 호출하십시오. – user1336087