SDUT-2121_数据结构实验之链表六:有序链表的建立

数据结构实验之链表六:有序链表的建立

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem Description

输入N个无序的整数,建立一个有序链表,链表中的结点按照数值非降序排列,输出该有序链表。

Input

第一行输入整数个数N;
第二行输入N个无序的整数。

Output

依次输出有序链表的结点值。

Sample Input

6
33 6 22 9 44 5

Sample Output

5 6 9 22 33 44

Hint

不得使用数组!

链表的插入操作,找到链表中第一大于或等于x的节点,将x插入该节点之前就好,注意考虑链表中没有大于x的节点的时候。

#include <stdio.h>
#include <string.h>
#include <stdlib.h>typedef struct node
{int data;struct node *next;
}link;link *newlink()
{link *t;t = (link*)malloc(sizeof(link));t->next = NULL;return t;
}link *insert(link *head,int x)
{link *p,*q,*r;r = newlink();r->data = x;p = head;while(p->next){q = p->next;if(q->data>=x){r->next = p->next;p->next = r;return head;}p = p->next;}r->next = p->next;p->next = r;return head;
}void show(link *head)
{link *p;p = head->next;while(p){if(p->next==NULL)printf("%d\n",p->data);elseprintf("%d ",p->data);p = p->next;}
}int main()
{link *head;int n,i,x;scanf("%d",&n);head = newlink();for(i=0;i<n;i++){scanf("%d",&x);head = insert(head,x);}show(head);return 0;
}

转载于:https://www.cnblogs.com/luoxiaoyi/p/9726720.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/389580.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

事件映射 消息映射_映射幻影收费站

事件映射 消息映射When I was a child, I had a voracious appetite for books. I was constantly visiting the library and picking new volumes to read, but one I always came back to was The Phantom Tollbooth, written by Norton Juster and illustrated by Jules Fei…

前端代码调试常用

转载于:https://www.cnblogs.com/tabCtrlShift/p/9076752.html

Pytorch中BN层入门思想及实现

批归一化层-BN层&#xff08;Batch Normalization&#xff09; 作用及影响&#xff1a; 直接作用&#xff1a;对输入BN层的张量进行数值归一化&#xff0c;使其成为均值为零&#xff0c;方差为一的张量。 带来影响&#xff1a; 1.使得网络更加稳定&#xff0c;结果不容易受到…

JDK源码学习笔记——TreeMap及红黑树

找了几个分析比较到位的&#xff0c;不再重复写了…… Java 集合系列12之 TreeMap详细介绍(源码解析)和使用示例 【Java集合源码剖析】TreeMap源码剖析 java源码分析之TreeMap基础篇 关于红黑树&#xff1a; Java数据结构和算法&#xff08;十一&#xff09;——红黑树 【数据结…

匿名内部类和匿名类_匿名schanonymous

匿名内部类和匿名类Everybody loves a fad. You can pinpoint someone’s generation better than carbon dating by asking them what their favorite toys and gadgets were as a kid. Tamagotchi and pogs? You were born around 1988, weren’t you? Coleco Electronic Q…

Pytorch框架中SGD&Adam优化器以及BP反向传播入门思想及实现

因为这章内容比较多&#xff0c;分开来叙述&#xff0c;前面先讲理论后面是讲代码。最重要的是代码部分&#xff0c;结合代码去理解思想。 SGD优化器 思想&#xff1a; 根据梯度&#xff0c;控制调整权重的幅度 公式&#xff1a; 权重(新) 权重(旧) - 学习率 梯度 Adam…

朱晔和你聊Spring系列S1E3:Spring咖啡罐里的豆子

标题中的咖啡罐指的是Spring容器&#xff0c;容器里装的当然就是被称作Bean的豆子。本文我们会以一个最基本的例子来熟悉Spring的容器管理和扩展点。阅读PDF版本 为什么要让容器来管理对象&#xff1f; 首先我们来聊聊这个问题&#xff0c;为什么我们要用Spring来管理对象&…

ab实验置信度_为什么您的Ab测试需要置信区间

ab实验置信度by Alos Bissuel, Vincent Grosbois and Benjamin HeymannAlosBissuel&#xff0c;Vincent Grosbois和Benjamin Heymann撰写 The recent media debate on COVID-19 drugs is a unique occasion to discuss why decision making in an uncertain environment is a …

基于Pytorch的NLP入门任务思想及代码实现:判断文本中是否出现指定字

今天学了第一个基于Pytorch框架的NLP任务&#xff1a; 判断文本中是否出现指定字 思路&#xff1a;&#xff08;注意&#xff1a;这是基于字的算法&#xff09; 任务&#xff1a;判断文本中是否出现“xyz”&#xff0c;出现其中之一即可 训练部分&#xff1a; 一&#xff…

erlang下lists模块sort(排序)方法源码解析(二)

上接erlang下lists模块sort&#xff08;排序&#xff09;方法源码解析(一)&#xff0c;到目前为止&#xff0c;list列表已经被分割成N个列表&#xff0c;而且每个列表的元素是有序的&#xff08;从大到小&#xff09; 下面我们重点来看看mergel和rmergel模块&#xff0c;因为我…

洛谷P4841 城市规划(多项式求逆)

传送门 这题太珂怕了……如果是我的话完全想不出来…… 题解 1 //minamoto2 #include<iostream>3 #include<cstdio>4 #include<algorithm>5 #define ll long long6 #define swap(x,y) (x^y,y^x,x^y)7 #define mul(x,y) (1ll*(x)*(y)%P)8 #define add(x,y) (x…

支撑阻力指标_使用k表示聚类以创建支撑和阻力

支撑阻力指标Note from Towards Data Science’s editors: While we allow independent authors to publish articles in accordance with our rules and guidelines, we do not endorse each author’s contribution. You should not rely on an author’s works without seek…

高版本(3.9版本)python在anaconda安装opencv库及skimage库(scikit_image库)诸多问题解决办法

今天开始CV方向的学习&#xff0c;然而刚拿到基础代码的时候发现 from skimage.color import rgb2gray 和 import cv2标红&#xff08;这里是因为我已经配置成功了&#xff0c;所以没有红标&#xff09;&#xff0c;我以为是单纯两个库没有下载&#xff0c;去pycharm中下载ski…

python 实现斐波那契数列

# coding:utf8 __author__ blueslidef fun(arg1,arg2,stop):if arg10:print(arg1,arg2)arg3 arg1arg2print(arg3)if arg3<stop:arg3 fun(arg2,arg3,stop)fun(0,1,100)转载于:https://www.cnblogs.com/bluesl/p/9079705.html

单机安装ZooKeeper

2019独角兽企业重金招聘Python工程师标准>>> zookeeper下载、安装以及配置环境变量 本节介绍单机的zookeeper安装&#xff0c;官方下载地址如下&#xff1a; https://archive.apache.org/dist/zookeeper/ 我这里使用的是3.4.11版本&#xff0c;所以找到相应的版本点…

均线交易策略的回测 r_使用r创建交易策略并进行回测

均线交易策略的回测 rR Programming language is an open-source software developed by statisticians and it is widely used among Data Miners for developing Data Analysis. R can be best programmed and developed in RStudio which is an IDE (Integrated Development…

opencv入门课程:彩色图像灰度化和二值化(采用skimage库和opencv库两种方法)

用最简单的办法实现彩色图像灰度化和二值化&#xff1a; 首先采用skimage库&#xff08;skimage库现在在scikit_image库中&#xff09;实现&#xff1a; from skimage.color import rgb2gray import numpy as np import matplotlib.pyplot as plt""" skimage库…

SVN中Revert changes from this revision 跟Revert to this revision

譬如有个文件&#xff0c;有十个版本&#xff0c;假定版本号是1&#xff0c;2&#xff0c;3&#xff0c;4&#xff0c;5&#xff0c;6&#xff0c;7&#xff0c;8&#xff0c;9&#xff0c;10。Revert to this revision&#xff1a; 如果是在版本6这里点击“Revert to this rev…

归 [拾叶集]

归 心归故乡 想象行走在 乡间恬静小路上 让那些疲惫的梦 都随风飞散吧&#xff01; 不去想那些世俗 人来人往 熙熙攘攘 秋日午后 阳光下 细数落叶 来日方长 世上的路 有诗人、浪子 歌咏吟唱 世上的人 在欲望、信仰中 彷徨 彷徨又迷茫 亲爱的人儿 快结束那 无休止的独自流浪 莫要…

instagram分析以预测与安的限量版运动鞋转售价格

Being a sneakerhead is a culture on its own and has its own industry. Every month Biggest brands introduce few select Limited Edition Sneakers which are sold in the markets according to Lottery System called ‘Raffle’. Which have created a new market of i…