普通链表

xiaoxiao2021-02-27  184

#include<bits/stdc++.h> struct node { int data; struct node *next; }; int main() { struct node *head,*p,*q,*t; int i,n,a; scanf("%d",&n); head = NULL; for(i=1;i<=n;i++) { scanf("%d",&a); p=(struct node *)malloc(sizeof(struct node)); p->data=a; p->next=NULL; if(head==NULL) head=p; else q->next=p; q=p; } scanf("%d",&a); t=head; while(t!=NULL) { if(t->next->data > a) { p=(struct node *)malloc(sizeof(struct node)); p->data=a; p->next=t->next; t->next=p; break; } t=t->next; } t=head; while(t!=NULL) { printf("%d ",t->data); t=t->next; } return 0; }
转载请注明原文地址: https://www.6miu.com/read-13842.html

最新回复(0)