原创 二分查找-遞歸和非遞歸

1、非遞歸實現 int search(int a[], int n, int key) { int h = 0; int t = n-1; int m; while(h < t) { int m = (h + t)>>1;

原创 可變參數

#include <stdio.h> #include <stdarg.h> int add(int n,...) { va_list v;//保存可以邊長的參數列表 va_start(v, n);//從n之後的所有參數保存之 i

原创 c++初始化

初識c++,需要知道兩點內容 1、c語言類型檢查較弱,而c++注重類型,強類型,嚴格檢查類型 2、c++初始化 #include <iostream> #include <stdlib.h> using namespace std; in

原创 關於字符串常考函數

1、strcpy 原型聲明:char *strcpy(char* dest, const char *src); 頭文件:#include <string.h> 和 #include <stdio.h> 功能:把從src地址開始且

原创 鏈表的增刪改查

1、增加(尾插) void backnode(node** ppnode, int num, typedata data )//尾插 { node *pnewnode = (node *)malloc(sizeof(node)); p

原创 數組的初始化和元素的刪除

以前只是知道,數組元素刪除與鏈表中元素刪除相比很麻煩,知道其中的原理,沒有真正做過,爲了避免眼高手低,特來練練 #include <stdio.h> #include <stdlib.h> #define length 10 int ma

原创 簡單的打印圖形

#include <stdio.h> #include <stdlib.h> int main() { int i, j, k, n; printf("input the n:\n"); scanf("%d", &n); for

原创 鏈表的插入排序

/* ========================== 功能:直接插入排序(由小到大) 返回:指向鏈表表 頭的指針 ========================== */ /* 直接插入排序的基本思想就是假設鏈表的前面n-1

原创 引用

一、引用的用途 1、變量的引用是變量的別名,與變量佔用同一段內存空間,引用在定義時需要初始化,不能爲空。 在函數內部使用 #include <iostream> #include <stdlib.h> using namespace s

原创 文件讀取

1、獲得文件大小 int getfilesize(char *path) { FILE *pf;//文件指針 pf = fopen(path, "r"); if(pf == NULL) { return -1; } el

原创 new 和 delete

一、delete 1、delete p 用於刪除數組利用的空間 #include <iostream> #include <stdlib.h> using namespace std; int main() { int *p = n

原创 二維數組的訪問方法

int main() { int a[3][4] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; int (*p)[4] = a; int i, j; for(i = 0; i < 3; i+

原创 sizeof與strlen

1、sizeof用來返回類型以及靜態分配的對象、結構或數組所佔的空間,其值在編譯時即計算好了。strlen返回字符串的長度。該字符串可能是自己定義的,也可能是內存中隨機的,該函數實際完成的功能是從代表該字符串的第一個地址開始遍歷,直到遇到

原创 c實現面向對象

c語言的結構體裏面沒有函數,但是c++裏面有函數,所以今天實現一個c語言面向對象的程序 1、封裝 #include <stdio.h> #include <stdlib.h> #include <string.h> typedef str

原创 優先級與結合性

優先級:同一個操作數,優先執行。例如:1+2-3+8*9,先執行8*9 結合性:優先級相等的情況下,計算的方向,例如:int a, b, c; a=b=c=10;從右向左 #include <stdio.h> int main() {