将斐波切纳函数存入链表,并插入一个数,使其保持升序


#include<stdio.h>
#include<stdlib.h>

typedef struct node{

    int data;
    struct node *next;

}Node;
int main()
{
    int number;
    Node *head,*p,*pre,*nex;
    pre=nex=p=(Node*)malloc(sizeof(Node));
    head=NULL;
    pre->data=1;
    p=pre->next;
    p->data=1;
    head=pre; 
    if(head!=NULL)
    {
        while((pre->data +p->data )<=100)
        nex=p->next;
        nex->data=pre->data+p->data;
        pre=p;
        p=nex;
        nex=nex->next;
    }
    nex->next=NULL;
    printf("函数:\n");
    p=head;
    while(head!=NULL)
    {
        printf("\n%d\t",p->data);
        p=p->next;
    }
    printf("insert number:\n");
    scanf("%d",&number);
    Node *n=(Node*)malloc(sizeof(Node));
    n->data=number;
    p=head;
    if(head!=NULL)
    {
        while(p->data<=number)
        p=p->next;
        pre->next=n;
        n->next=p;
    }
    p=head;
    while(head!=NULL)
    {
        printf("\n%d\t",p->data);
        p=p->next;
    }
    return 0;
}