#include<stdio.h>
#include<stdlib.h>
struct node
{
int a;
struct node* next;
};
int main()
{
struct node *head,*p,*q,*t;
head = NULL;
q = NULL;
//p = NULL;
int n,b;
printf("請輸入n個數字");
scanf_s("%d", &n);
for (int i = 1; i <= n; i++)
{
scanf_s("%d", &b);
p = (struct node *)malloc(sizeof(struct node));
p->a=b;
p->next = NULL;
if (head == NULL)
{
head = p;
}
else
{
q->next = p;
}
q = p;
}
printf("請輸入要插入的數字");
scanf_s("%d", &b);
t = head;
while (t != NULL)
{
if (t->next == NULL || t->next->a > b)
{
p = (struct node*)(sizeof(struct node));
p->a = b;//此處為啥不能讀入
p->next = t->next;
t->next = p;
break;
}
t = t->next;
}
t = head;
while (t != NULL)
{
printf("%d", t->a);
t = t->next;
}
system("pause");
return 0;
}
uj5u.com熱心網友回復:
if (t->next == NULL || t->next->a > b)
{
// p = (struct node*)(sizeof(struct node));
p = (struct node*)malloc(sizeof(struct node));
p->a = b;//此處為啥不能讀入
p->next = t->next;
t->next = p;
break;
}
uj5u.com熱心網友回復:
p = (struct node*)(sizeof(struct node));
p->a = b;//此處為啥不能讀入
這個是什么語法?
是要malloc嗎
uj5u.com熱心網友回復:
暈啦,malloc沒打上去,怎么看都沒看你出問題
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/205168.html
標籤:C語言
