1
0

5 Revīzijas 550de23a29 ... e9b5ad068b

Autors SHA1 Ziņojums Datums
  XuZiang e9b5ad068b one 5 mēneši atpakaļ
  XuZiang 550de23a29 dll 5 mēneši atpakaļ
  XuZiang 67f741b7cb add_dll 5 mēneši atpakaļ
  XuZiang e5bf356840 Homework_text 5 mēneši atpakaļ
  XuZiang 6615dea6c3 first homework 5 mēneši atpakaļ
5 mainītis faili ar 150 papildinājumiem un 0 dzēšanām
  1. 67 0
      HomeWork_1.cpp
  2. BIN
      HomeWork_1_1.exe
  3. 0 0
      README.md
  4. BIN
      Sort_NumDll.dll
  5. 83 0
      第一次提交/HomeWork_1.cpp

+ 67 - 0
HomeWork_1.cpp

@@ -0,0 +1,67 @@
+#include <iostream>
+#include <ctime>      // 随机数种子头文件 
+using namespace std;
+
+void generate_rand(int Size/*I*/, int num[]/*I*/)
+{
+	for (int i = 0; i < Size; i++)
+	{
+		num[i] = rand() % 100 + 1;
+	}
+
+	cout << "生成的随机数组:" << endl;
+	for (int i = 0; i < Size; i++)
+	{
+		cout << num[i] << " ";
+	}
+	cout << endl;
+}
+
+void sort_num(int Size/*I*/, int num[]/*I*/)
+{
+
+	for (int i = 0; i < Size - 1; i++)          // 对比总轮数
+	{
+		for (int j = 0; j < Size - i - 1; j++) // 每轮对比次数
+		{
+			if (num[j] > num[j + 1])
+			{
+				// 交换元素
+				int temp = num[j];
+				num[j] = num[j + 1];
+				num[j + 1] = temp;
+			}
+		}
+	}
+}
+
+void result(int Size/*I*/, int num[]/*I*/)
+{
+	cout << "排序后的数组:" << endl;
+	for (int i = 0; i < Size; i++)
+	{
+		cout << num[i] << " ";
+	}
+	cout << " " << endl;
+}
+
+int main()
+{
+	// 设置随机数种子
+	srand(time(NULL)); //防止每次生成随机数一样
+
+	const int Size = 10;
+	int num[Size];
+
+	// 1.生成随机数并查看
+	generate_rand(Size, num);
+
+	// 2.使用冒泡排序对随机数进行排序
+	sort_num(Size, num);
+
+	// 3.输出排序结果
+	result(Size, num);
+
+	system("pause");
+	return 0;
+}

BIN
HomeWork_1_1.exe


+ 0 - 0
README.md


BIN
Sort_NumDll.dll


+ 83 - 0
第一次提交/HomeWork_1.cpp

@@ -0,0 +1,83 @@
+/*HEAD homework 1 HOMEWORK */
+/*==============================================================================
+2024年度随机数排序程序设计作业
+================================================================================
+File description:
+这是第一次作业演示的样板程序。
+提交者:徐子昂
+邮 箱: dutxza@163.com
+
+================================================================================
+Date            Name            Description of Change
+05/20/2024      Xu Ziang        Created.
+$HISTORY$
+================================================================================
+*/
+
+#include <iostream>
+#include <ctime>      // 随机数种子头文件 
+using namespace std;
+
+void generate_rand(int Size/*I*/, int num[]/*I*/)
+{
+	for (int i = 0; i < Size; i++)
+	{
+		num[i] = rand() % 100 + 1;
+	}
+
+	cout << "生成的随机数组:" << endl;
+	for (int i = 0; i < Size; i++)
+	{
+		cout << num[i] << " ";
+	}
+	cout << endl;
+}
+
+void sort_num(int Size/*I*/, int num[]/*I*/)
+{
+
+	for (int i = 0; i < Size - 1; i++)          // 对比总轮数
+	{
+		for (int j = 0; j < Size - i - 1; j++) // 每轮对比次数
+		{
+			if (num[j] > num[j + 1])
+			{
+				// 交换元素
+				int temp = num[j];
+				num[j] = num[j + 1];
+				num[j + 1] = temp;
+			}
+		}
+	}
+}
+
+void result(int Size/*I*/, int num[]/*I*/)
+{
+	cout << "排序后的数组:" << endl;
+	for (int i = 0; i < Size; i++)
+	{
+		cout << num[i] << " ";
+	}
+	cout << " " << endl;
+}
+
+int main()
+{
+	// 设置随机数种子
+	srand(time(NULL)); //防止每次生成随机数一样
+
+	const int Size = 10;
+	int num[Size];
+
+	// 1.生成随机数并查看
+	generate_rand(Size, num);
+
+	// 2.使用冒泡排序对随机数进行排序
+	sort_num(Size, num);
+
+	// 3.输出排序结果
+	result(Size, num);
+
+	system("pause");
+	return 0;
+}