数据结构实验之链表六:有序链表的建立(SDUT 2121)
#include <bits/stdc++.h>
using namespace std;
struct node
{
int data;
struct node *next;
};
int main()
{
int n;
struct node *head,*tail,*p,*q,*t;
scanf("%d",&n);
head = new node;
head -> next = NULL;
tail = head;
for(int i = 0; i < n; i ++)
{
p = new node;
p -> next = NULL;
scanf("%d",&p->data);
if(head -> next == NULL){
tail -> next = p;
tail = p;
}
else {
int f = 1;
q = head;
t = q -> next;
while(t)
{
if(p->data > t -> data){
q = q ->next;
t = t -> next;
}
else {
p->next =q ->next;
q -> next = p;
f = 0;
break;
}
}
if(f) {tail -> next = p;
tail = p;}
}
}
for(p = head -> next; p != NULL; p = p -> next)
{
if(p==head->next)printf("%d",p->data);
else printf(" %d", p -> data);
}
printf("\n");
return 0;
}
数据结构实验之链表六:有序链表的建立(SDUT 2121)的更多相关文章
- 数据结构实验之查找六:顺序查找(SDUT 3378)
(不知道为啥开个数组就 TLE .QAQ) #include <stdio.h> #include <stdlib.h> #include <string.h> / ...
- SDUT OJ 3403 数据结构实验之排序六:希尔排序
数据结构实验之排序六:希尔排序 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descrip ...
- SDUT 3403 数据结构实验之排序六:希尔排序
数据结构实验之排序六:希尔排序 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 我们已经学习 ...
- SDUT-3403_数据结构实验之排序六:希尔排序
数据结构实验之排序六:希尔排序 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 我们已经学习了各种排序方法,知道在不同的 ...
- SDUT 3345 数据结构实验之二叉树六:哈夫曼编码
数据结构实验之二叉树六:哈夫曼编码 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 字符的编 ...
- SDUT OJ 数据结构实验之图论六:村村通公路(最小生成树)
数据结构实验之图论六:村村通公路 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descri ...
- SDUT OJ 数据结构实验之二叉树六:哈夫曼编码
数据结构实验之二叉树六:哈夫曼编码 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descr ...
- SDUT 3362 数据结构实验之图论六:村村通公路
数据结构实验之图论六:村村通公路 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Problem Description 当前农村公 ...
- SDUT-3378_数据结构实验之查找六:顺序查找
数据结构实验之查找六:顺序查找 Time Limit: 1000 ms Memory Limit: 65536 KiB Problem Description 在一个给定的无序序列里,查找与给定关键字 ...
- Java单链表、双端链表、有序链表实现
单链表: insertFirst:在表头插入一个新的链接点,时间复杂度为O(1) deleteFirst:删除表头的链接点,时间复杂度为O(1) 有了这两个方法,就可以用单链表来实现一个栈了,见htt ...
随机推荐
- 怎样获取页面中所有带href属性的标签集合
使用: document.links document.links instanceof HTMLCollection; 注意: 1. a 标签和 area 标签可以设置 href属性, 因此可以被获 ...
- select into from与insert into select区别
创建一个table2 向table2中插入 table1中name为11的所有行(前提table2不存在) select * into table2 from table1 where name=‘ ...
- docker部署redis
镜像获取 docker pull redis:4.0 ##当前最新版本 docker images 启动 docker run --name redis-huiyuan -p : -v $PWD/da ...
- Core项目部署到IIS上delete、put谓词不支持
解决方法:在web.config的system.webServer结点下添加如下代码 <modules runAllManagedModulesForAllRequests="true ...
- javascript数字格式化通用类——accounting.js使用
简介 accounting.js 是一个非常小的JavaScript方法库用于对数字,金额和货币进行格式化.并提供可选的Excel风格列渲染.它没有依赖任何JS框架.货币符号等可以按需求进行定制. 代 ...
- String Class
#include <iostream> #include <fstream> #include <sstream> using namespace std; tem ...
- h5学习之表单
<html> <head> <title>新型input类型及表单新元素</title> <meta charset="utf-8&qu ...
- vue常用知识点
vue中图片路径写法 <img :src="avatorSrc" alt=""> <img :src="avatorSrc2&quo ...
- 每日命令:(7)mv
mv命令是move的缩写,可以用来移动文件或者将文件改名(move (rename) files),是Linux系统下常用的命令,经常用来备份文件或者目录. 1.命令格式: mv [选项] 源文件或目 ...
- 使用Response下载(支持任何格式)
使用Response下载 下面代码: protected void Button2_Click(object sender, EventArgs e) { Response.ContentType = ...