最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

C編程輔導:ECE222 Vectors And Matrices

2022-10-25 15:23 作者:拓端tecdat  | 我要投稿

原文鏈接:tecdat.cn/?p=29614

Requirement

In this lab, each student is to write a program that allows the user to manipulate the entries in?vector, or in a?matrix. The program should keep track of one vector of variable length, and one matrix of exactly 4x4 size. The program should enter a loop, displaying a set of options (given below). Once the user selects an option, the program should display the vector (or matrix, as appropriate) before and after the operation chosen by the user. For example, if the user selects “reverse vector” and the current vector is [-3 0 2 5] then the program should display:

input ? -3 0 2 5 ? reversed ? 5 2 0 -1 復制代碼

The program should run until the user selects an option to quit.
The program must use the following structure definitions.

struct vector { ? float *data; ? int ? ?size; }; struct matrix { ? struct vector rows[4]; }; 復制代碼

Analysis

Vectors和Matrices,矢量和矩陣,也稱一維和二維數(shù)組。屬于C語言很常見的數(shù)據(jù)結(jié)構(gòu)。本題要實現(xiàn)的是矢量的反轉(zhuǎn),以及矩陣的轉(zhuǎn)置。
反轉(zhuǎn)和轉(zhuǎn)置需要用到排序算法,這里我們采用Quicksort,也就是快速排序。

Tips

矢量反轉(zhuǎn)所用的快速排序算法如下

int parition(struct vector *vec, int left, int right) { ? float piovt, temp; ? int i, j; ? piovt = *(vec[left]); ? i = left; ? j = right + 1; ? while (1) { ? ? do { ? ? ? ++i; ? ? } while (*(vec[i]) <= piovt && i <= right); ? ? do { ? ? ? --j; ? ? } while (*(vec[j]) > piovt); ? ? if (i >= j) { ? ? ? break; ? ? } ? ? temp = *(vec[i]); ? ? *(vec[i]) = *(vec[j]); ? ? *(vec[j]) = temp; ? } ? temp = *(vec[left]); ? *(vec[left]) = *(vec[right]); ? *(vec[right]) = temp; ? return j; } ? void quick_sort(struct vector *vec, int left, int right) { ? int i; ? if (left < right) { ? ? i = partition(vec, left, right); ? ? quick_sort(vec, left, right - 1); ? ? quick_sort(vec, i + 1, right); ? } } 復制代碼


C編程輔導:ECE222 Vectors And Matrices的評論 (共 條)

分享到微博請遵守國家法律
彩票| 湖州市| 织金县| 安塞县| 佳木斯市| 宁都县| 泰安市| 宁化县| 兖州市| 南陵县| 嘉兴市| 肃北| 乌兰察布市| 南召县| 青阳县| 赤城县| 神池县| 津南区| 嘉义县| 石泉县| 临泽县| 邻水| 申扎县| 探索| 界首市| 宜宾市| 绥江县| 临泉县| 兴文县| 香港| 天全县| 江北区| 焦作市| 崇信县| 阳西县| 永宁县| 濮阳县| 蓬安县| 克山县| 汶上县| 苏尼特左旗|