数组插入
来源:互联网 发布:流程图软件visio2016 编辑:程序博客网 时间:2024/05/29 15:19
数组插入
对于已经排好序的数组, 只需找到新的数应该插入哪个位置, 然后把插入点之后的所有元素向后挪, 腾出位置后插入新的数即可.
注意, 在挪动后面的数时, 应该从最后面那个数开始, 依次向前.
我写的这个程序除了实现了插入功能外, 还利用一个do while循环实现了多次反复操作. 感兴趣的同学可以看一下.
===========数组插入 by claydodo============
对于已经排好序的数组, 只需找到新的数应该插入哪个位置, 然后把插入点之后的所有元素向后挪, 腾出位置后插入新的数即可.
注意, 在挪动后面的数时, 应该从最后面那个数开始, 依次向前.
我写的这个程序除了实现了插入功能外, 还利用一个do while循环实现了多次反复操作. 感兴趣的同学可以看一下.
===========数组插入 by claydodo============
- #include <stdio.h>
- #define MAX_SIZE 256
- int main()
- {
- int array[MAX_SIZE] =
- { 10, 20, 30, 40, 50, 60};
- int now_size=6;
- int i;
- for(i=0;i<now_size;i++)
- printf("%d ", array[i]);
- printf("/n");
- char choice='y';
- do
- {
- //Input a new number
- printf("Please input a number to insert: ");
- int new_num;
- scanf("%d", &new_num);
- //Find out where to insert
- int find_pos;
- for(find_pos=0; find_pos<now_size; find_pos++)
- {
- if(array[find_pos]>new_num)
- break;
- }
- //Move everyone behind the insert position backward
- int j;
- for(j=now_size-1;j>=find_pos; j--)
- array[j+1]=array[j];
- //Put the new number into the array
- array[find_pos]=new_num;
- //Update the array size
- now_size++;
- //Output the result
- for(j=0;j<now_size;j++)
- printf("%d ", array[j]);
- printf("/n");
- //Whether to insert aother number?
- //Take care of the space in " %c".
- printf("Insert another number? (y/n): ");
- scanf(" %c",&choice);
- }
- while( (choice != 'N') && (choice != 'n') && (now_size < MAX_SIZE) );
- return 0;
- }
- 数组插入
- 数组插入
- 数组插入
- 数组中插入另一个数组
- 有序数组 插入元素
- 简单的插入数组
- 数组插入数据
- 插入并排序数组
- 数组元素的插入
- 插入排序(数组)
- 字符数组的插入
- 面试:数组:插入位置
- 数组排序-插入排序
- 数组排序---插入排序
- 数组-插入元素
- C 数组插入排序
- 数组插入排序
- 插入有序数组中
- vim的设置文档
- datawindow的数据源为存储过程的注意事项
- 在vmware上跑ecos (wanglibo_2004@yahoo.com.cn)
- 装机
- 移动增值业务随笔(2)
- 数组插入
- 网站优化方法(精选)及SEO实例参考
- ASP.NET MVC 入门1、简介
- 关于窗口
- 神经网络入门连载之三
- 一个理解wait()与notify()的例子
- variant_t与_bstr_t
- DX灯光与材质
- JAD作为Eclipse反编译插件