|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
为什么节点没有链接起来
- #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;
- }
复制代码
把这个去掉
|
|