原创 對單鏈表逆置,不能建立新節點,只能通過已有節點重新組合
算法思想:把鏈表從表頭拆開,用頭插法從開始節點往表頭插入,就完成了逆置 代碼: #include <iostream> #include <stdio.h> #include <stdlib.h> using namespace std;
原创 刪除順序表L中下標爲i~j的元素
#include <iostream> #include <stdio.h> #include <stdlib.h> #define maxsize 100 using namespace std; typedef struct{ i
原创 順序表 :數組A[N],N小於等於9,只用數組A和i來找到最小值
#include <iostream> #include <stdio.h> #include <stdlib.h> using namespace std; void findmin(int *A,int N) { int i=
原创 逆序打印單鏈表(遞歸)
#include <iostream> #include <stdio.h> #include <stdlib.h> using namespace std; typedef struct LNode{ int data; str
原创 已知遞增單鏈表A和B,求集合A和集合B的差集,保存在鏈表A中
算法思想:只需將鏈表A中共有的節點刪除即可。定義指針p,q分別指向A,B的頭結點,當A中元素小於B的時,p右移一位(B類似操作),值相等時,刪除該節點,任一指針爲空時停止循環 代碼: #include <iostream> #in
原创 斐波拉契數列(遞歸)
#include<stdio.h> #include<math.h> #include<string.h> int fb(int a1,int a2,int n) { if(n>0) { printf("%