출력을 출력 할 사용자 정의 함수를 만드는 방법에 조금 얽혀 있습니다. 또한 각 노드의 데이터를 합산하여 합계를 인쇄하는 사용자 정의 함수를 만들어야하지만 올바르게 합치는 것은 아니며 형식도 약간 떨어져 있습니다.C에서 사용자 정의 함수 및 연결된 목록
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
char printout();
int sum();
typedef struct node
{
int number;
struct node*next;
} node;
char printout()
{
};
int sum()
{
int s,sum_all=0, node_sum=0;
for(s=0;s=100;s++)
{
sum_all=node_sum+s;
return printf("The sum of all nodes is %d.\n",sum_all);
};
};
int main()
{
srand (time(NULL));
int i, total=0;
struct node*head=malloc(sizeof(struct node));
head->number = rand()%100;
printf("Node #%d contains %d.\n", 0, head->number);
struct node*here=head;
for (i=1; i<100; i++)
{
here->next=malloc(sizeof(struct node));
here->number=rand()%100;
printf("Node #%d contains %d.\n", i, here->number);
};
total=sum(here->number);
printf("%2.2d", total);
return 0;
}
나는 삽입이 어떻게 작동하는지 보지 못한다 :(당신은 'here-> next'를 반복 할 때마다 루프를 매번 저장하지 않고 덮어 쓰지 않는다. 즉, 링크 된 목록에 관한 것은 요소들이 실제로 연결될 것입니다 :) – ThingyWotsit
첫 번째 반복에서 리턴을 할 때'sum' 함수에서'for' 루프의 요점은 무엇입니까! –
함수의 반환 유형이'printout'' char'입니까? – BLUEPIXY