陣列遞迴
逆序輸出
#include
void preprint(int a,int n);
int main()
;preprint(a,6);
return 0;
}void preprint(int a,int n)
}逆序輸出2
#include
void preprint(int a,int n);
int main()
;preprint(a,6);
printf("\n");
return 0;
}void preprint(int a,int n)
}求陣列元素和
#include
int preprint(int a,int n);
int main()
;sum = preprint(a,5);
printf("%d",sum);
printf("\n");
return 0;
}int preprint(int a,int n)
else
}求最大值
#include
int max(int a,int n);
int main()
;m = max(a,5);
printf("%d",m);
printf("\n");
return 0;
}int max(int a,int n)
else
return max;}}
逆置儲存
#include
void exchange(int a,int n);
int main()
;exchange(a,6);
for(i = 0;i < 6;i++)
printf("\n");
return 0;
}void exchange(int a,int n)
}鍊錶遞迴
#include
#include
typedef struct node
elemsn;
elemsn * createlink(int a,int n);//建立
void printlink(elemsn *h);//列印
void printnode(elemsn *h);//正向輸出
void reprintnode(elemsn *h);//逆向輸出
int sumnode(elemsn *h);//求節點和
int oddnode(elemsn *h);//求奇數和
elemsn * keynode(elemsn *h,int key);//找key的位址
int minnode(elemsn *h);//找最小值
int main()
;int sum,odd,key,min;
printf("請輸入值key: ");
scanf("%d",&key);
head = createlink(a,5);
printf("鍊錶為:");
printlink(head);
printf("\n");
//正向輸出
printf("正向輸出結果:");
printnode(head);
printf("\n");
//逆向輸出
printf("逆向輸出結果:");
reprintnode(head);
printf("\n");
//返回所有節點和
printf("節點和為:");
sum = sumnode(head);
printf("%d \n",sum);
//奇數節點個數
printf("奇數節點個數為:");
odd = oddnode(head);
printf("%d \n",odd);
//尋找鍊錶最小值
min = minnode(head);
printf("最小值為:%d\n",min);
//返回值為key的位址
key = keynode(head,key);
if(key == null)
else
return 0;
}elemsn * createlink(int a,int n)
return h;
}void printlink(elemsn *h)
}void printnode(elemsn *h)
}void reprintnode(elemsn *h)
}int sumnode(elemsn *h)
else
}int oddnode(elemsn *h)
else
return cnt;}}
elemsn * keynode(elemsn *h,int key)
else
else}}
int minnode(elemsn *h)
else
return min;}}
#include
#include
typedef struct node
elemsn;
elemsn * createlink(int a,int n);
void printlink(elemsn *h);
int main()
;elemsn *head;
//遞迴建立
head = createlink(a,5);
printlink(head);
printf("\n");
return 0;
}void printlink(elemsn *h)
}elemsn * createlink(int a,int n)
else
}
C語言資料結構之排序部分
氣泡排序 include void bubblesort int a,int n int main bubblesort a,8 for i 0 i 8 i printf n return 0 void bubblesort int a,int n 改進 include void bubblesor...
C語言資料結構之鍊錶部分(2)
2.鍊錶的一些練習 1 輸出尾結點元素 include include define n 5 typedef struct node elemsn elemsn createlink1 int a void printlink elemsn h int main elemsn head null h...
C語言資料結構之鍊錶部分(10)
10.練習 統計單向鍊錶的每個元素出現的次數 include include define n 11 typedef struct node elemsn elemsn createlink int a void printlink elemsn h int main 建立 head createl...