ITfeng

 

2012年4月26日

大数相乘问题--解决方案

摘要: #include<stdio.h>#include<stdlib.h>#include<string.h>void mutiply(char*a,char*b,char*res){int len1,len2,len;char temp;int*result;int i=0,j;int startFlag=0;len1=strlen(a);len2=strlen(b);len=len1+len2+1;result=(int *)malloc(len*4);for(i=0;i<len;i++)result[i]=0;for(i=0;i<len1/2; 阅读全文

posted @ 2012-04-26 21:18 ITfeng 阅读(236) 评论(0) 推荐(0) 编辑

2012年4月24日

排序----归并排序

摘要: 归并排序的前提是:归并前两个数组是有序的。归并排序的思路是先分成两半使用归并排序,然后比较大小,从小到大复制到一个零时数组中去;如果比较后,一方有剩余,那么将剩下的复制到临时数组,最后将排序好的数组拷贝回原数组。归并排序的时间复杂度是:nlogn#include<stdio.h>#include<stdlib.h>#define N 1000000int array[N];int temp[N];void init_array(int a[],int n);void print_array(int a[],int n);void guibing_sort(int a[] 阅读全文

posted @ 2012-04-24 16:32 ITfeng 阅读(306) 评论(0) 推荐(0) 编辑

排序----快速排序(方法2)

摘要: 这种快速排序的思路是:首先以a[start]为轴,不停得从数组的两端开始比较。从最右端开始,如果有比a[start]小的,那么赋值a[i];从最左端开始,如果有比a[start]大的,那么赋值a[j],以此往复,渐渐有序;注意的是递归跳出的条件,只有一个数就不需要排序,即start>=end#include<stdio.h>#include<stdlib.h>#define N 1000000int array[N];void init_array(int a[],int n);void print_array(int a[],int n);void quick_ 阅读全文

posted @ 2012-04-24 15:55 ITfeng 阅读(208) 评论(0) 推荐(0) 编辑

排序----快速排序(方法1)

摘要: 快速排序的思路是:首先拿a[start]作为轴,将原数组中比a[start]小的放small数组,将原数组中比a[start]大的放big数组,最后在将small数组 和a[start]值和big数组中的数复制回原数组。以此递归,使数组逐渐有序。快速排序的平均时间复杂度是nlogn。#include<stdio.h>#include<stdlib.h>#define N 1000000int array[N];int small[N];int big[N];void init_array(int a[],int n);void print_array(int a[],i 阅读全文

posted @ 2012-04-24 15:28 ITfeng 阅读(237) 评论(0) 推荐(0) 编辑

排序----插入排序

摘要: 插入排序的思路是:新插入的数与比它前面的数进行比较,如果新插入的数比它前面的数小,那么比它前面的数后移;否则,就找到了新插入的数的位置插入排序的时间复杂度是:O(n^2)#include<stdio.h>#include<stdlib.h>#define N 100int array[N];void init_array(int a[],int n);void print_array(int a[],int n);void insert_sort(int a[],int n);int main(){init_array(array,N);insert_sort(arra 阅读全文

posted @ 2012-04-24 14:46 ITfeng 阅读(274) 评论(0) 推荐(0) 编辑

2012年4月23日

排序---选择排序

摘要: 选择排序的思路是:先假定一个数十最小的,后面的数与之比较,如果比它小,那么记录下标,替换最小值;依次往复,则排序完毕选择排序的时间复杂度是o(n^2)#include<stdio.h>#include<stdlib.h>#define N 100int buffer[N];void init_array(int a[],int n);void print_array(int a[],int n);void select_array(int a[],int n);int main(){init_array(buffer,N);printf("before sor 阅读全文

posted @ 2012-04-23 16:21 ITfeng 阅读(212) 评论(0) 推荐(0) 编辑

排序---冒泡

摘要: 冒泡排序的思路是将最大的数或者最小的数移到最右端或者最左端第一层for循环的意思是一共比较多少趟,第二层for循环的意思是每次需要比较多少次冒泡排序的时间复杂度是o(n^2)#include<stdio.h>#include<stdlib.h>#define N 100int table[N];void init_array(int array[],int n);void print_array(int array[],int n);void bubble_sort(int array[],int n);int main(){init_array(table,N);pr 阅读全文

posted @ 2012-04-23 16:00 ITfeng 阅读(140) 评论(0) 推荐(0) 编辑

双向链表

摘要: #include<stdio.h>#include<stdlib.h>typedef struct list{int data;struct list*left;struct list*right;}List;void insert_list_2nd(List*head,int data);void insert_list_last(List*head,int data);void insert_list_order(List*head,int data);void print_list(List*head);void delete_list(List*head,int 阅读全文

posted @ 2012-04-23 14:54 ITfeng 阅读(154) 评论(0) 推荐(0) 编辑

不带头结点的链表操作----插入删除打印

摘要: #include<stdio.h>#include<stdlib.h>typedef struct list{int data;struct list*next;}List;List*insert_list_2nd(List*head,int data);List*insert_list_last(List*head,int data);List*insert_list_order(List*head,int data);void print_list(List*head);List*delete_list(List*head,int value);int main() 阅读全文

posted @ 2012-04-23 14:10 ITfeng 阅读(457) 评论(0) 推荐(0) 编辑

2012年4月22日

链表的操作-三种插入法,删除,打印

摘要: //链表有序插入和删除最重要的是预判,就是判断下一个是否满足要求,因为如果只是判断当前,那么当你找到要操作的节点时,已经过了指向该节点的指针//删除的时候注意释放空间#include<stdio.h>#include<stdlib.h>typedef struct list{int data;struct list*next;}List;void insert_list_2nd(List*head,int data);//表头插入 void insert_list_last(List*head,int data);//表尾插入 void insert_list_orde 阅读全文

posted @ 2012-04-22 22:15 ITfeng 阅读(264) 评论(0) 推荐(0) 编辑

导航