Problem 2647 --Getting Started - Insertion Sort

2647: Getting Started - Insertion Sort

"
Time Limit $1$ 秒/Second(s) Memory Limit $512$ 兆字节/Megabyte(s)
提交总数 $625$ 正确数量 $543$
裁判形式 标准裁判/Standard Judge 我的状态 尚未尝试
难度 分类标签 STL 排序

Insertion Sort 

Write a program of the Insertion Sort algorithm which sorts a sequence A in ascending order. The algorithm should be based on the following pseudocode:

 for i = 1 to A.length-1 

 key = A[i]

 /* insert A[i] into the sorted sequence A[0,...,j-1] */

 j = i - 1 

 while j >= 0 and A[j] > key

 A[j+1] = A[j] 

 j-- 

 A[j+1] = key

 Note that, indices for array elements are based on 0-origin.

 To illustrate the algorithms, your program should trace intermediate result for each step.

The first line of the input includes an integer N, the number of elements in the sequence. 

In the second line, N elements of the sequence are given separated by a single space.

The output consists of N lines. Please output the intermediate sequence in a line for each step. Elements of the sequence should be separated by single space.
6
5 2 4 6 1 3
5 2 4 6 1 3
2 5 4 6 1 3
2 4 5 6 1 3
2 4 5 6 1 3
1 2 4 5 6 3
1 2 3 4 5 6
1 ≤  N ≤  100

推荐代码 查看2647 所有题解 上传题解视频得图灵币

本题记录 用 户(点击查看用户) 运行号(点击购买题解) 时 间
算法最快[$0 $ms] 沈超 1060274 2024-01-12 13:25:15
内存最少[$0 $KB] soul 608076 2020-07-21 21:23:02
第一AC 找队友,能刷题的那种 328871 2018-11-25 00:22:06
第一挑战 刘成健 322017 2018-11-21 11:30:32

赛题来源/所属竞赛 会津大学《挑战数据结构与算法》 挑战数据结构与算法

竞赛编号 竞赛名称 竞赛时间 访问比赛
1786 2023-2024-1学期《程序设计技能实训》排序和线性表【23计算机】 2023-12-18 00:00:00 请登录
1682 2021-2022-2学期<算法分析与设计> 第3周练习:递归和基础排序 2022-03-07 08:00:00 请登录
1608 2020-2021-2学期<算法分析与设计>第4周练习:排序算法 2021-03-15 08:00:00 请登录
1571 2020-2021-1学期《程序设计技能实训》基础排序【20计算机12345】 2020-12-22 09:00:00 请登录
1528 2020年《图灵信息学算法》第一单元:排序和查找 2020-07-19 14:30:00 请登录