Professional Documents
Culture Documents
FDDSDF
FDDSDF
EE2120 資料結構
Programming Exercise?
簡易報告
甲班
2023/09/16
一、 目的
請說明此程式練習之目的。
(字體:新細明體,大小:14,單行間距,左右對齊)
運用亂數出來的數字進行比較大小的排序並插入數字,再來就是
使用 performance analysis 並列出 worst case & best case,最後使用
clock()來計算最壞和最好情況下程序的執行時間。
二、 程式碼與執行結果
請列出最後版本之程式碼,並將執行結果之截圖貼附於本節中。
(字體:新細明體,大小:14,單行間距,左右對齊)
/
***********************************************************
***
EE2120 Data Structure
Programming Exercise #2 working template
Goals:
I. Programming implementation of Insertion Sort Algorithm
II. Performance Analysis and Measurements for the program
Wen-Yen Lin
wylin@mail.cgu.edu.tw
Department of Elecetrical Engineering
Chang Gung University
***********************************************************
****/
// These are the header files that you will need in this exercise
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <time.h>
// Used in Part I
// & Part II for performance measurement
void InsertionSort(int a[], int n)
{
//For you to do: Implement the algorithm of Insertion Sort here.
//a[] is the initial input array with number of n integers to be
//sorted out in ascending order. The sorted array is still put in
//a[].
int i;
void main()
{
int i, n, counter;
int a[MAX_SIZE];
clock_t start;
double initializeTime, elaspedTime;
//Note: You have to understand what would be the worst case and
best case and initialize
//your input sequence accordingly.
//Performance Measurement
//Mesaurement the execution time of the Insertion Sort Algorithm
//using clock() as we introduced in the class. Find out the duration of
worst case and
//best case for n = 10, 20, 30, ..., 100, 200, ..., 1000. Plot your results
v.s. n
printf("CLOCKS_PER_SEC=%d\n", CLOCKS_PER_SEC);
printf("=========== Performance Measurement Worst Case Test
============\n");
n = 10;
while (n <= 1000) {
// to measure the time needed for initializing the test case into
worst case first.
counter = 0;
start = clock();
do {
counter++;
//For you to do. The way to initialize the a[] into worst case
//................
for (i = 0; i < n; i++)
a[i] = n - i;
//Write down the operation counts and step counts as well as the
execution time,
//then, use the Excel template file provided for the plot
}
三、 所遇到之問題與解決方式
請列出 3 項於本程式練習中,所碰到之程式撰寫錯誤或是警告,
並說明解決方法。
(字體:新細明體,大小:14,單行間距,左右對齊)
問題一:
錯誤或警告:連結器工具錯誤 LNK2019
解決方法:檢查後重新將 InsertionSort 輸入好
問題二:
錯誤或警告:連結器工具錯誤 LNK1120
解決方法:同上檢查後重新將 InsertionSort 輸入好
四、 討論與心得
請討論於練習中之學習心得,若此程式練習有題目需要回答,
請於本章節中回答。
(字體:新細明體,大小:14,單行間距,左右對齊)
距離之前使用 Visual Studio 大概是一年多前,確實忘了蠻多東
西的,也希望老師語速能放緩一些讓我跟同學能吸收得進去。