《算法導論》實踐1-實踐工程搭建

  最近工作之餘開始學習《算法導論》,這本書涉及內容偏理論,又難啃,所以經過深思熟慮,決定現階段暫不去關注其中定理證明,基本概念這一塊,因爲對自己目前用處不大,這一遍過《算法導論》的目標是將其中列舉的算法逐一用C++實現。

  從本文開始記錄實踐過程,也好有大家的督促,本文記錄實踐項目工程搭建:用vs新建一個C++控制檯應用程序,命名IntroductionToAlgorithm,然後新建一個篩選器,我準備按照書中的文檔組織方式組織篩選器這樣方便對應查找,目錄結構如下:

…IntroductionToAlgorithm
…Projects
…第一部分:基礎知識
…Chapter_2.h/cpp
…Chapter_4.h/cpp

…頭文件
…源文件
…IntroductionToAlgorithm.cpp
…stdafx.cpp

在IntroductionToAlgorithm.cpp中寫入代碼:

#include "stdafx.h"
#include "iostream"
#include<string>
#include <vector>
#include <ctime>
using namespace std;



int _tmain(int argc, _TCHAR* argv[])
{
	
	std::cout << "請輸入算法序號:" << std::endl;
	std::cout << "1:插入排序" << std::endl;
	std::cout << "2:歸併排序" << std::endl;
	std::cout << "0:退出" << std::endl;

	int  algorithmnum = -1;	
	 
	std::cin >> algorithmnum;
	while (algorithmnum != 0)
	{
		switch (algorithmnum)
		{
		case 1:
		{
			

		}
			break;
		case 2:
		{
			

		}
			break;
		default:
			break;
		}
		std::cout << "請輸入算法序號:" << std::endl;
		std::cout << "1:插入排序" << std::endl;
		std::cout << "2:歸併排序" << std::endl;
		std::cout << "0:退出" << std::endl;
		std::cin >> algorithmnum;
	}	
	
	return 0;
}

   然後程序運行起來,輸入1,則進入插入排序運行,輸入2,進入歸併排序,輸入0,退出,可以循環調用,直到輸入0爲止,我們以後加其他算法可以依次往後排,3、4、5、6…。
   好啦,這樣搭建了一個簡單的環境,以後我們也可以在這個工程裏面清晰地加代碼。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章