
/*
Sudo Game 4*4
*/
#include<iostream>
#include<iomanip>
#include<ctype.h>
flyinsky76 發表在 痞客邦 留言(0) 人氣(153)

#include<iostream>
#include<iomanip>
#include<stdlib.h>
#include<time.h>
using namespace std;
flyinsky76 發表在 痞客邦 留言(0) 人氣(273)
來聽首歌吧
本來上youtube想說聽點歌
結果 "This video is not available in your country.
"
flyinsky76 發表在 痞客邦 留言(0) 人氣(42)

#include<iostream>
#include<time.h>
#include<iomanip>
#include<stdlib.h>
using namespace std;
#define size 10
#define start 0
void Swap(int &a,int &b)
{
int buf;
buf = a;
a = b;
b = buf;
}
void InsertionSort(int *array)
{
for(int i = start+1;i<size;i++)
{
int j = i;
while( j>0 && array[j]<array[j-1] )
{
Swap( array[j] , array[j-1] );
j--;
}
}
}
int main()
{
srand(time(0));
int *array = new int[size];
int time1,time2;
cout<<"Oringinal List: ";
for(int i = start;i<size;i++)
{
array[i] = rand()%20+1;
cout<<setiosflags(ios::right)<<setw(5)<<array[i];
}
cout<<endl<<endl;
time1 = time(0);
InsertionSort(array);
time2 = time(0);
cout<<"After List: ";
for(int j = start;j<size;j++)
{
cout<<setiosflags(ios::right)<<setw(5)<<array[j];
}
cout<<endl<<endl;
cout<<"Time: "<<time2-time1<<" Seconds"<<endl<<endl;
return 0;
}
flyinsky76 發表在 痞客邦 留言(0) 人氣(79)

#include<iostream>
#include<time.h>
#include<iomanip>
#include<stdlib.h>
using namespace std;
#define size 10
#define start 0
void Swap(int &a,int &b)
{
int buf;
buf = a;
a = b;
b = buf;
}
void SelectionSort(int *array)
{
int min;
for(int i = start;i<size;i++)
{
min = i;
for(int j = i+1;j<size;j++)
{
if( array[j] < array[min] )
min = j;
}
Swap(array[i],array[min]);
}
}
int main()
{
srand(time(0));
int *array = new int[size];
int time1,time2;
cout<<"Oringinal List: ";
for(int i = start;i<size;i++)
{
array[i] = rand()%20+1;
cout<<setiosflags(ios::right)<<setw(5)<<array[i];
}
cout<<endl<<endl;
time1 = time(0);
SelectionSort(array);
time2 = time(0);
cout<<"After List: ";
for(int j = start;j<size;j++)
{
cout<<setiosflags(ios::right)<<setw(5)<<array[j];
}
cout<<endl<<endl;
cout<<"Time: "<<time2-time1<<" Seconds"<<endl<<endl;
return 0;
}
flyinsky76 發表在 痞客邦 留言(0) 人氣(35)
雞仔用慣了Visual C++現在用gdb除錯還真不習慣 XD
但凡事總要有第一次嘛
慢慢適應囉
flyinsky76 發表在 痞客邦 留言(0) 人氣(175)

非常方便的一套IDE (尤其是java)
來安裝吧!!
flyinsky76 發表在 痞客邦 留言(0) 人氣(292)

#include<iostream>
#include<stdlib.h> //Ubuntu中的亂數需具此HeadFile
#include<time.h>
#include<iomanip>
using namespace std;
#define size 10
#define start 0
void Swap(int &a,int &b)
{
int buf;
buf = a;
a = b;
b = buf;
}
void BubbleSort(int array[])
{
for(int i = size-1;i>start;i--)
{
for(int j = start;j<i;j++)
{
if( array[j] > array[j+1] )
Swap(array[j],array[j+1]);
}
}
}
int main()
{
srand(time(0));
int *array = new int[size];
cout<<"Oringinal List: ";
for(int i=start;i<size;i++)
{
array[i] = i;
array[i] = rand()%20+1; //1~20
cout<<setiosflags(ios::right)<<setw(5)<<array[i];
}
cout<<endl<<endl;
BubbleSort(array);
cout<<"After List: ";
for(int j=start;j<size;j++)
{
cout<<setiosflags(ios::right)<<setw(5)<<array[j];
}
cout<<endl<<endl;
return 0;
}
flyinsky76 發表在 痞客邦 留言(0) 人氣(31)

/*
Binary Search
*/
#include<iostream>
using namespace std;
#define size 10
#define start 0
bool BinarySearch(int array[],int num)
{
int p = start,r = size,middle;
while(p<r)
{
middle = (p+r)/2;
if( array[middle] == num )
return true;
else
{
if( array[middle] > num )
{
r = middle-1;
}
else
{
p = middle+1;
}
}
}
return false;
}
int main()
{
int num,array[size];
cout<<"The number list: ";
for(int i=start;i<sizeof(array)/4;i++)
{
array[i] = i;
cout<<array[i]<<" ";
}
cout<<endl<<endl;
cout<<"input number:";
cin>>num;
if( BinarySearch(array,num) == true )
{
cout<<"Find the number in the list: "<<num<<endl;
}
return 0;
}
flyinsky76 發表在 痞客邦 留言(0) 人氣(58)

安裝: sudo apt-get install g++
flyinsky76 發表在 痞客邦 留言(0) 人氣(20)