原创 鏈表的建立插入與刪除
//file 鏈表的建立插入與刪除.cpp #include"iostream.h"#include"string.h"#include"stdlib.h" struct listnode{ //鏈表結點的類型聲明 int num; ch
原创 文件的讀與寫操作
//文件的讀與寫操作.cpp #include <iostream.h>#include"fstream.h"#include<stdlib.h> #define SIZE 2 typedef struct{ char name[10];
原创 C++面試題之螺旋隊列
//螺旋隊列.cpp// 21 22 ... ...// 20 7 8 9 10// 19 6 1 2 11// 18 5 4 3 12// 17 16 15 14 13//看
原创 最大公約數的遞歸解法
//最大公約數.cpp #include<iostream>using namespace std;int gcd(int m,int n){ if(m%n==0) return n; else return gcd(n,m%n);}
原创 組合問題算法
//file 組合.cpp //將5角錢幣換成5分和1角硬幣的各種組合 #include"iostream.h" void main(void) { int x5,y1; for(y1=0;y1<=5;y1++){ x5=10-2*y1;
原创 C++面試題之宏定義面試題
//宏定義面試題1.cpp//What is the output of the following code?[中國臺灣某著名殺毒軟件公司2005年10月面試題]#include<stdio.h>#define SQR(x) (x*x)
原创 單鏈表的常用基本操作
//單鏈表的常用基本操作.cpp #include<iostream>using namespace std; typedef struct Node{ char name[10]; int age,score; struct Node*
原创 常用正則表達式
(1)匹配中文字符的正則表達式:[/u4e00-/u9fa5] 評註:匹配中文還真是個頭疼的事,有了這個表達式就好辦了 (2)匹配雙字節字符(包括漢字在內):[^/x00-/xff] 評註:可以用來計算字符串的長度(一個雙字節字符
原创 文件操作
//file 文件操作例.cpp // 編寫一個程序,統計一個文本文件中以英文字母開頭的行各有多少,// 並輸出統計結果。// 例如文件f1.txt的內容如下:// abbb123// acccc234// c111111
原创 冒泡排序
//file 冒泡排序1.cpp //例:將有10個元素的數組用冒泡排序法按升序排列 // 冒泡排序(設按升序)算法://// 第一趟兩兩比較:從第一個元素(0下標)開始進行相鄰兩個元素的比較,// 若前者比後者大,則兩者交換位置,再
原创 走臺階問題算法
/* 分析: 1 步臺階只有1種走法(1) 2步臺階2種(11、2) 3步臺階有3種(111、12、21) 4 步臺階有5種(1111、112、121、211、22) 5 步臺階有8種(11111、1112、1121、1211、122、2
原创 漢偌塔問題
//file 漢諾塔問題.cpp ///////////////////////////////////////////////////////////////// 漢諾塔問題://// 有三根柱子編號爲1,2,3,其中1號柱上有若干個大
原创 快速排序
//file 快速排序.cpp #include"iostream.h" void quick_sort(int [],int,int); void main(void){ int array[]={36,-73,-65,45,97,
原创 文件複製操作
//文件複製操作.cpp#include<iostream.h>#include<fstream.h> //有關文件輸入、輸出的定義文件#include<stdlib.h> void main(){ char ch; fstream
原创 C++面試題之類型轉換面試題
//類型轉換面試題.cpp char foo(void){ unsigned int a=6; int b=-20; char c; (a+b>6)?(c=1):(c=0); return c;} //解析: unsigned int 類