Requirement

In this lab, each student is to write a program that allows the user to manipulate the entries in , or in a . 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:

1
2
3
4
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.

1
2
3
4
5
6
7
8
struct vector {
float *data;
int size;
};

struct matrix {
struct vector rows[4];
};

Analysis

Vectors和Matrices,和,也稱一維和二維。屬于C語言很常見的數據結構。本題要實現的是矢量的反轉,以及矩陣的轉置。
留学生作业代写,网课代修-英国、澳大利亚、北美代写等反轉和轉置需要用到排序算法,這里我們采用,也就是。

Tips

矢量反轉所用的快速排序算法如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
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);
}
}

19 分類
51 標簽
微信
Essay_Cheery
郵箱
[email protected]

在線客服

售前咨詢
售后咨詢
微信號
Essay_Cheery
微信

在線客服

售前咨詢
售后咨詢
微信號
Essay_Cheery
微信