Advertisement

实现功能模块用于链表添加

阅读量:

输入包含两行内容。第一行由四个按照非递减顺序排列的数据组成,各数据之间以空格分隔。

第二行给出一个整数p。

insert的作用是将p放置于第一行四个数中的适当位置,确保插入之后的五个数依然保持非递减的顺序。

输出结果

复制代码
    #include<stdio.h>
    #include<stdlib.h>
    
    struct node
    {
     int x;
     struct node *next;
    };
    // 非递减有序单链表;是指从小到大有序啊,即递增;
    //但又没说是单调递增,说明允许有重复的数据
    void insert(struct node *H,int p)
    {
    	struct node *temp; 
    	struct node *ph=H->next;
    	while(1)
    	{
    		if(p>=ph->x&&p<=ph->next->x)
    		{
    			temp=ph;
    			struct node *ph=(struct node *)malloc(sizeof(struct node));
    			ph->next=temp->next;//把要插入的结点的地址指向下一个 //后接 
    			temp->

全部评论 (0)

还没有任何评论哟~