收藏 分销(赏)

我爱新浪微博讲课讲稿.doc

上传人:丰**** 文档编号:3816489 上传时间:2024-07-21 格式:DOC 页数:5 大小:21.50KB 下载积分:6 金币
下载 相关 举报
我爱新浪微博讲课讲稿.doc_第1页
第1页 / 共5页
我爱新浪微博讲课讲稿.doc_第2页
第2页 / 共5页


点击查看更多>>
资源描述
我爱新浪微博 精品资料 实验4 数组 本次实验将练习数组的用法。完成一个程序,该程序要求用户输入整数,并按照输入顺序记录进一个数组。当用户输入-1时标识结束输入结束。程序将记录的数组的顺序进行反序,即原数组第一个数与最后一个数进行交换,依此类推。反序后的数组进行输出在屏幕上。最后对数组进行从小到大排序,并输出排序结果。程序的一次运行结果如下。你可以运行作业材料中附带的已经完成的array.exe程序来了解更多的该程序的输入和输出要求。 Enter numbers, one per line, ending with the sentinel value -1 The program will then display those values in reverse order and sorted order. ? 9 ? 3 ? 7 ? 9 9 is already in the array. Please input again ? 3 3 is already in the array. Please input again ? 1 ? 2 ? 6 ? 19 ? -1 The reverse array is as follows: 19 6 2 1 7 3 9 The sorted array is as follows: 1 2 3 6 7 9 19 作业提示: 1. 该程序的主程序和常量定义已经在作业材料的array.cpp中给出,你不能进行改变。 2. 程序中需要完成的函数的功能和使用方法如下,你可以增添新的函数,但是你必须在主程序中正确地写出这些函数的原型并实现这些函数的功能。 /* * Function: GetIntegerArray * Usage: n = GetIntegerArray(array, max, sentinel); * ------------------------------------------------- * This function reads elements into an integer array by * reading values, one per line, from the keyboard. The end * of the input data is indicated by the parameter sentinel. * The caller is responsible for declaring the array and * passing it as a parameter, along with its allocated * size. The value returned is the number of elements * actually entered and therefore gives the effective size * of the array, which is typically less than the allocated * size given by max. If the user types in more than max * elements, GetIntegerArray generates an error. */ /* * Function: PrintIntegerArray * Usage: PrintIntegerArray(array, n); * ----------------------------------- * This function displays the first n values in array, * one per line, on the console. */ /* * Function: ReverseIntegerArray * Usage: ReverseIntegerArray(array, n); * ------------------------------------- * This function reverses the elements of array, which has n as * its effective size. The procedure operates by going through * the first half of the array and swapping each element with * its counterpart at the end of the array. */ /* * Function: SwapIntegerElements * Usage: SwapIntegerElements(array, p1, p2); * ------------------------------------------ * This function swaps the elements in array at index * positions p1 and p2. */ /* * Function: GiveInstructions * Usage: GiveInstructions(); * -------------------------- * This function gives instructions for the array reversal program. */ /* * Function: SortIntegerArray * -------------------------- * This implementation uses an algorithm called selection sort, * which can be described in English as follows. With your left * hand, point at each element in the array in turn, starting at * index 0. At each step in the cycle: * * (1) Find the smallest element in the range between your left * hand and the end of the array, and point at that element * with your right hand. * * (2) Move that element into its correct index position by * switching the elements indicated by your left and right * hands. */ /* * Function: FindSmallestInteger * Usage: index = FindSmallestInteger(array, low, high); * ----------------------------------------------------- * This function returns the index of the smallest value in the * specified array of integers, searching only between the index * positions low and high, inclusive. It operates by keeping track * of the index of the smallest so far in the variable spos. If the * index range is empty, the function returns low. */ /* * Function: SearchArray * Usage: bool = SearchArray(array, n, value); * ----------------------------------------------------- * This function search the specified array of integers. If value is in the specified array * then return ture, otherwise return false. */ 3. 函数SortIntegerArray要求采用选择排序法对数组进行排序,这是一种简单的排序算法。你可以在学习了课本7.8节的插值排序算法后完成选择排序算法,并比较它们的不同。选择排序算法的具体算法在函数说明里有详细描述。 4. 函数SearchArray是对数组元素进行查找,你可以采用课本第7章7.7节中学到的简单的线性查找算法来实现。对于一个已经排序的数组你可以考虑用更好的搜索算法来实现该函数。阅读课本第20章获得对于排序和搜索算法的更多知识。 仅供学习与交流,如有侵权请联系网站删除 谢谢5
展开阅读全文

开通  VIP会员、SVIP会员  优惠大
下载10份以上建议开通VIP会员
下载20份以上建议开通SVIP会员


开通VIP      成为共赢上传

当前位置:首页 > 教育专区 > 其他

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服