单链表
为什么节点没有链接起来#include <stdio.h>
#include <stdlib.h>
struct Node
{
int value;
struct Node *next;
};
void get(struct Node *n)
{
scanf("%d",&n->value);
}
void insertNode(struct Node **head)
{
struct Node *previous;
struct Node *current;
struct Node *n;
current = *head;
previous = NULL;
n = (struct Node *)malloc(sizeof(struct Node));
get(n);
if(n->value==-1)
{
exit(1);
}
if(*head==NULL);
{
*head=n;
n->next=NULL;
return;
}
while(current!=NULL&&(current->value)<(n->value))
{
previous=current;
current=current->next;
}
if(previous==NULL)
{
*head=n;
}
else
{
previous->next = n;
}
n->next=current;
}
void printNode(struct Node *head)
{
struct Node *current;
current = head;
while (current != NULL)
{
printf("%d ", current->value);
current = current->next;
}
putchar('\n');
}
int main(void)
{
struct Node *head = NULL;
printf("开始测试插入整数...\n");
while (1)
{
printf("请输入一个整数(输入-1表示结束):");
insertNode(&head);
printNode(head);
}
return 0;
} if(*head==NULL);
{
*head=n;
n->next=NULL;
return;
}
把这个去掉
页:
[1]