kinve 4 anni fa
commit
3e1e37a664
54 ha cambiato i file con 375 aggiunte e 0 eliminazioni
  1. 55 0
      1.选择排序.c
  2. 72 0
      2.冒泡排序.c
  3. 53 0
      3.插入排序.c
  4. 50 0
      4.快速排序.c
  5. 70 0
      5.归并排序.c
  6. 37 0
      6.顺序查找.c
  7. 36 0
      7.二分查找.c
  8. 1 0
      README.md
  9. BIN
      数据结构和算法Flash动画演示/B树的删除.swf
  10. BIN
      数据结构和算法Flash动画演示/B树的生长过程.swf
  11. 1 0
      数据结构和算法Flash动画演示/testArray.txt
  12. BIN
      数据结构和算法Flash动画演示/三元组表的转置.swf
  13. BIN
      数据结构和算法Flash动画演示/中序线索化二叉树.swf
  14. BIN
      数据结构和算法Flash动画演示/串的顺序存储.swf
  15. BIN
      数据结构和算法Flash动画演示/二分查找.swf
  16. BIN
      数据结构和算法Flash动画演示/二叉排序树的删除.swf
  17. BIN
      数据结构和算法Flash动画演示/二叉排序树的生成.swf
  18. BIN
      数据结构和算法Flash动画演示/二叉树的建立.swf
  19. BIN
      数据结构和算法Flash动画演示/克鲁斯卡尔算法构造最小生成树.swf
  20. BIN
      数据结构和算法Flash动画演示/冒泡排序.swf
  21. BIN
      数据结构和算法Flash动画演示/分块查找.swf
  22. BIN
      数据结构和算法Flash动画演示/单链表结点的删除.swf
  23. BIN
      数据结构和算法Flash动画演示/单链表结点的插入.swf
  24. BIN
      数据结构和算法Flash动画演示/图的深度优先遍历.swf
  25. BIN
      数据结构和算法Flash动画演示/基数排序.swf
  26. BIN
      数据结构和算法Flash动画演示/堆排序.swf
  27. BIN
      数据结构和算法Flash动画演示/头插法建单链表.swf
  28. BIN
      数据结构和算法Flash动画演示/寻找中序线索化二叉树指定结点的前驱.swf
  29. BIN
      数据结构和算法Flash动画演示/寻找中序线索化二叉树指定结点的后继.swf
  30. BIN
      数据结构和算法Flash动画演示/尾插法建表.swf
  31. BIN
      数据结构和算法Flash动画演示/希儿排序.swf
  32. BIN
      数据结构和算法Flash动画演示/开放定址法建立散列表.swf
  33. BIN
      数据结构和算法Flash动画演示/循环队列操作演示.swf
  34. BIN
      数据结构和算法Flash动画演示/快速排序.swf
  35. BIN
      数据结构和算法Flash动画演示/拉链法创建散列表.swf
  36. BIN
      数据结构和算法Flash动画演示/拓扑排序.swf
  37. BIN
      数据结构和算法Flash动画演示/最短路径.swf
  38. BIN
      数据结构和算法Flash动画演示/朴素串匹配算法过程示意.swf
  39. BIN
      数据结构和算法Flash动画演示/构造哈夫曼树的算法模拟.swf
  40. BIN
      数据结构和算法Flash动画演示/构造哈夫曼树过程.swf
  41. BIN
      数据结构和算法Flash动画演示/栈与递归.swf
  42. BIN
      数据结构和算法Flash动画演示/树、森林和二叉树的转换.swf
  43. BIN
      数据结构和算法Flash动画演示/桶式排序法.swf
  44. BIN
      数据结构和算法Flash动画演示/直接插入排序.swf
  45. BIN
      数据结构和算法Flash动画演示/直接选择排序.swf
  46. BIN
      数据结构和算法Flash动画演示/规并排序.swf
  47. BIN
      数据结构和算法Flash动画演示/邻接表表示的图的广度优先遍历.swf
  48. BIN
      数据结构和算法Flash动画演示/邻接表表示的图的深度优先遍历.swf
  49. BIN
      数据结构和算法Flash动画演示/顺序查找.swf
  50. BIN
      数据结构和算法Flash动画演示/顺序栈(4个存储空间).swf
  51. BIN
      数据结构和算法Flash动画演示/顺序栈(8个存储空间).swf
  52. BIN
      数据结构和算法Flash动画演示/顺序表的删除运算.swf
  53. BIN
      数据结构和算法Flash动画演示/顺序表的插入.swf
  54. BIN
      数据结构和算法Flash动画演示/顺序队列操作.swf

+ 55 - 0
1.选择排序.c

@@ -0,0 +1,55 @@
+#include<stdio.h>
+#include<stdlib.h>
+
+#define N 8
+
+void select_sort(int a[],int n);
+
+
+//选择排序实现
+void select_sort(int a[],int n)//n为数组a的元素个数
+{
+	int i,j;
+	int min_index;
+	int temp;
+    //进行N-1轮选择
+    for(i=0; i<n-1; i++)
+    {
+        min_index = i; 
+        //找出第i小的数所在的位置
+        for(j=i+1; j<n; j++)
+        {
+            if(a[j] < a[min_index])
+            {
+                min_index = j;
+            }
+        }
+
+        //将第i小的数,放在第i个位置;如果刚好,就不用交换
+        if( i != min_index)
+        {
+            temp = a[i];
+            a[i] = a[min_index];
+            a[min_index] = temp;
+        }
+    }
+}
+
+
+int  main()
+{
+	int i;
+    int num[N] = {89, 38, 11, 78, 96, 44, 19, 25};
+
+    select_sort(num, N);
+
+    for(i=0; i<N; i++)
+        printf("%d  ", num[i]);
+
+    printf("\n");
+
+
+    system("pause");
+    return 0;
+
+}

+ 72 - 0
2.冒泡排序.c

@@ -0,0 +1,72 @@
+#include<stdio.h>
+#include<stdlib.h>
+
+typedef enum { false, true } bool;
+
+#define N 8
+
+void bubble_sort(int a[],int n);
+
+
+//一般实现
+void bubble_sort(int a[],int n)//n为数组a的元素个数
+{
+	int i,j;
+    //一定进行N-1轮比较
+    for(i=0; i<n-1; i++)
+    {
+        //每一轮比较前n-1-i个,即已排序好的最后i个不用比较
+        for(j=0; j<n-1-i; j++)
+        {
+            if(a[j] > a[j+1])
+            {
+                int temp = a[j];
+                a[j] = a[j+1];
+                a[j+1]=temp;
+            }
+        }
+    }
+}
+
+//优化实现
+void bubble_sort_better(int a[],int n)//n为数组a的元素个数
+{
+	int i,j;
+	bool isSorted;
+	int temp;
+    //最多进行N-1轮比较
+    for(i=0; i<n-1; i++)
+    {
+        isSorted = true;
+        //每一轮比较前n-1-i个,即已排序好的最后i个不用比较
+        for(j=0; j<n-1-i; j++)
+        {
+            if(a[j] > a[j+1])
+            {
+                isSorted = false;
+                temp = a[j];
+                a[j] = a[j+1];
+                a[j+1]=temp;
+            }
+        }
+        if(isSorted) break; //如果没有发生交换,说明数组已经排序好了
+    }
+}
+
+
+int  main()
+{
+	int i;
+    int num[N] = {89, 38, 11, 78, 96, 44, 19, 25};
+
+    bubble_sort(num, N); //或者使用bubble_sort_better(num, N);
+
+    for(i=0; i<N; i++)
+        printf("%d  ", num[i]);
+
+    printf("\n");
+
+
+    system("pause");
+    return 0;
+}

+ 53 - 0
3.插入排序.c

@@ -0,0 +1,53 @@
+#include<stdio.h>
+#include<stdlib.h>
+
+#define N 8
+
+void insert_sort(int a[],int n);
+
+
+//插入排序实现,这里按从小到大排序
+void insert_sort(int a[],int n)//n为数组a的元素个数
+{
+	int i,j,k;
+	int temp;
+    //进行N-1轮插入过程
+    for(i=1; i<n; i++)
+    {
+        //首先找到元素a[i]需要插入的位置
+        j=0;
+        while( (a[j]<a[i]) && (j<i))
+        {
+            j++;
+        }
+
+        //将元素插入到正确的位置
+        if(i != j)  //如果i==j,说明a[i]刚好在正确的位置
+        {
+            temp = a[i];
+            for(k = i; k > j; k--)
+            {
+                a[k] = a[k-1];
+            }
+            a[j] = temp;
+        }
+    }
+}
+
+
+int  main()
+{
+	int i;
+    int num[N] = {89, 38, 11, 78, 96, 44, 19, 25};
+
+    insert_sort(num, N);
+
+    for(i=0; i<N; i++)
+        printf("%d  ", num[i]);
+
+    printf("\n");
+
+
+    system("pause");
+    return 0;
+}

+ 50 - 0
4.快速排序.c

@@ -0,0 +1,50 @@
+#include <stdio.h>
+#include <stdlib.h>
+#define N 6
+
+int partition(int arr[], int low, int high){
+    int key;
+    key = arr[low];
+    while(low<high){
+        while(low <high && arr[high]>= key )
+            high--;
+        if(low<high)
+            arr[low++] = arr[high];
+        while( low<high && arr[low]<=key )
+            low++;
+        if(low<high)
+            arr[high--] = arr[low];
+    }
+    arr[low] = key;
+
+    return low;
+}
+
+void quick_sort(int arr[], int start, int end){
+    int pos;
+    if (start<end){
+        pos = partition(arr, start, end);
+        quick_sort(arr,start,pos-1);
+        quick_sort(arr,pos+1,end);
+    }
+
+    return;
+}
+
+int main(void){
+    int i;
+    int arr[N]={32,12,7, 78, 23,45};
+
+    printf("ÅÅÐòǰ \n");
+    for(i=0;i<N;i++)
+        printf("%d\t",arr[i]);
+    quick_sort(arr,0,N-1);
+
+    printf("\n ÅÅÐòºó \n");
+    for(i=0; i<N; i++)
+        printf("%d\t", arr[i]);
+    printf ("\n");
+
+    system("pause");
+    return 0;
+}

+ 70 - 0
5.归并排序.c

@@ -0,0 +1,70 @@
+#include <stdio.h>
+#include <stdlib.h>
+#define N 7
+
+void merge(int arr[], int low, int mid, int high){
+    int i, k;
+    int *tmp = (int *)malloc((high-low+1)*sizeof(int));
+    //申请空间,使其大小为两个
+    int left_low = low;
+    int left_high = mid;
+    int right_low = mid + 1;
+    int right_high = high;
+
+    for(k=0; left_low<=left_high && right_low<=right_high; k++){  // 比较两个指针所指向的元素
+        if(arr[left_low]<=arr[right_low]){
+            tmp[k] = arr[left_low++];
+        }else{
+            tmp[k] = arr[right_low++];
+        }
+    }
+
+    if(left_low <= left_high){  //若第一个序列有剩余,直接复制出来粘到合并序列尾
+    //memcpy(tmp+k, arr+left_low, (left_high-left_low+l)*sizeof(int));
+    for(i=left_low;i<=left_high;i++)
+        tmp[k++] = arr[i];
+    }
+
+    if(right_low <= right_high){
+    //若第二个序列有剩余,直接复制出来粘到合并序列尾
+    //memcpy(tmp+k, arr+right_low, (right_high-right_low+1)*sizeof(int));
+        for(i=right_low; i<=right_high; i++)
+            tmp[k++] = arr[i];
+    }
+
+    for(i=0; i<high-low+1; i++)
+        arr[low+i] = tmp[i];
+    free(tmp);
+    return;
+}
+
+void merge_sort(int arr[], unsigned int first, unsigned int last){
+    int mid = 0;
+    if(first<last){
+        mid = (first+last)/2; /* 注意防止溢出 */
+        /*mid = first/2 + last/2;*/
+        //mid = (first & last) + ((first ^ last) >> 1);
+        merge_sort(arr, first, mid);
+        merge_sort(arr, mid+1,last);
+        merge(arr,first,mid,last);
+    }
+    return;
+}
+
+int main(){
+    int i;
+    int a[N]={32,12,56,78,76,45,36};
+
+    printf ("排序前 \n");
+    for(i=0;i<N;i++)
+        printf("%d\t",a[i]);
+
+    merge_sort(a,0,N-1);  // 排序
+
+    printf ("\n 排序后 \n");
+    for(i=0;i<N;i++)
+        printf("%d\t",a[i]); printf("\n");
+
+    system("pause");
+    return 0;
+}

+ 37 - 0
6.顺序查找.c

@@ -0,0 +1,37 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <memory.h>
+
+int ordersearch(int a[], int n, int des){
+    int i;
+    for(i=0; i<n; i++)
+        if(des==a[i])
+            return 1;
+
+    return 0;
+}
+
+int main(){
+    int i, val;
+    int a[8] = {32,12,56,78,76,45,43,98};
+    int ret;
+
+    for(i=0; i<8; i++)
+        printf("%d\t", a[i]);
+   
+    printf("\n请输入所要查找的元素:");
+    while(1){
+        scanf("%d", &val);
+        fflush(stdin);
+        ret = ordersearch(a, 8, val);
+
+        if(1 == ret)
+            printf ("查找成功!");
+        else
+            printf ("查找失败!");
+
+        printf("\n请输入所要查找的元素:");
+    }
+
+    return 0;
+}

+ 36 - 0
7.二分查找.c

@@ -0,0 +1,36 @@
+#include <stdio.h>
+
+binarySearch(int a[], int n, int key){
+    int low = 0;
+    int high = n - 1;
+    while(low<= high){
+        int mid = (low + high)/2;
+        int midVal = a[mid];
+        if(midVal<key)
+            low = mid + 1;
+        else if(midVal>key)
+            high = mid - 1;
+        else
+            return mid;
+    }
+    return -1;
+}
+
+int main(){
+    int i, val, ret;
+    int a[8]={-32, 12, 16, 24, 36, 45, 59, 98};
+    for(i=0; i<8; i++)
+        printf("%d\t", a[i]);
+
+    printf("\n请输人所要查找的元素:");
+    scanf("%d",&val);
+
+    ret = binarySearch(a,8,val);
+
+    if(-1 == ret)
+        printf("查找失败 \n");
+    else
+        printf ("查找成功 \n");
+
+    return 0;
+}

+ 1 - 0
README.md

@@ -0,0 +1 @@
+排序与查找算法

BIN
数据结构和算法Flash动画演示/B树的删除.swf


BIN
数据结构和算法Flash动画演示/B树的生长过程.swf


+ 1 - 0
数据结构和算法Flash动画演示/testArray.txt

@@ -0,0 +1 @@
+25,18,46,2,53,39,32,4,74,67

BIN
数据结构和算法Flash动画演示/三元组表的转置.swf


BIN
数据结构和算法Flash动画演示/中序线索化二叉树.swf


BIN
数据结构和算法Flash动画演示/串的顺序存储.swf


BIN
数据结构和算法Flash动画演示/二分查找.swf


BIN
数据结构和算法Flash动画演示/二叉排序树的删除.swf


BIN
数据结构和算法Flash动画演示/二叉排序树的生成.swf


BIN
数据结构和算法Flash动画演示/二叉树的建立.swf


BIN
数据结构和算法Flash动画演示/克鲁斯卡尔算法构造最小生成树.swf


BIN
数据结构和算法Flash动画演示/冒泡排序.swf


BIN
数据结构和算法Flash动画演示/分块查找.swf


BIN
数据结构和算法Flash动画演示/单链表结点的删除.swf


BIN
数据结构和算法Flash动画演示/单链表结点的插入.swf


BIN
数据结构和算法Flash动画演示/图的深度优先遍历.swf


BIN
数据结构和算法Flash动画演示/基数排序.swf


BIN
数据结构和算法Flash动画演示/堆排序.swf


BIN
数据结构和算法Flash动画演示/头插法建单链表.swf


BIN
数据结构和算法Flash动画演示/寻找中序线索化二叉树指定结点的前驱.swf


BIN
数据结构和算法Flash动画演示/寻找中序线索化二叉树指定结点的后继.swf


BIN
数据结构和算法Flash动画演示/尾插法建表.swf


BIN
数据结构和算法Flash动画演示/希儿排序.swf


BIN
数据结构和算法Flash动画演示/开放定址法建立散列表.swf


BIN
数据结构和算法Flash动画演示/循环队列操作演示.swf


BIN
数据结构和算法Flash动画演示/快速排序.swf


BIN
数据结构和算法Flash动画演示/拉链法创建散列表.swf


BIN
数据结构和算法Flash动画演示/拓扑排序.swf


BIN
数据结构和算法Flash动画演示/最短路径.swf


BIN
数据结构和算法Flash动画演示/朴素串匹配算法过程示意.swf


BIN
数据结构和算法Flash动画演示/构造哈夫曼树的算法模拟.swf


BIN
数据结构和算法Flash动画演示/构造哈夫曼树过程.swf


BIN
数据结构和算法Flash动画演示/栈与递归.swf


BIN
数据结构和算法Flash动画演示/树、森林和二叉树的转换.swf


BIN
数据结构和算法Flash动画演示/桶式排序法.swf


BIN
数据结构和算法Flash动画演示/直接插入排序.swf


BIN
数据结构和算法Flash动画演示/直接选择排序.swf


BIN
数据结构和算法Flash动画演示/规并排序.swf


BIN
数据结构和算法Flash动画演示/邻接表表示的图的广度优先遍历.swf


BIN
数据结构和算法Flash动画演示/邻接表表示的图的深度优先遍历.swf


BIN
数据结构和算法Flash动画演示/顺序查找.swf


BIN
数据结构和算法Flash动画演示/顺序栈(4个存储空间).swf


BIN
数据结构和算法Flash动画演示/顺序栈(8个存储空间).swf


BIN
数据结构和算法Flash动画演示/顺序表的删除运算.swf


BIN
数据结构和算法Flash动画演示/顺序表的插入.swf


BIN
数据结构和算法Flash动画演示/顺序队列操作.swf