文章

5

粉丝

34

获赞

0

访问

1.0k

头像
单链表 题解:
P1015 贵州大学机试题
发布于2024年3月27日 21:56
阅读数 183

C语言  边输入一个数据边进行链表插入 了解一下

#include<stdio.h>
typedef struct Node{
    int num;
    struct Node *Next;
}node;
int main(){
    node *head,*s,*ptr;
    head = (node *)malloc(sizeof(node));
    head -> Next = NULL;
    ptr = (node *) malloc(sizeof(node));
    int i =5,x;
    while(i--){
        scanf("%d",&x);
        s = (node *) malloc(sizeof (node));
        s -> num = x;
        ptr = head;
        if(ptr->Next == NULL){
            ptr -> Next = s;
            s -> Next = NULL;
        }else{
            while(ptr->Next != NULL){
                if(ptr->Next->num > x){
    &...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发