
数据结构与算法学习
文章平均质量分 73
xielechuan
低调做人,高调做事。全身心的投入自己热爱的事情中......
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
Sorting Algorithms--Quicksort
When deciding on the best sorting algorithm we often look at its worst-case running time, and base our decision solely on that factor. That is why beginning programmers often overlook quicksort as a viable option because of its T(n^2) worst-case running ti转载 2010-10-11 16:00:00 · 308 阅读 · 0 评论 -
使用指向函数的指针
指向函数的指针最常用到的是把函数作为参数传递给另一个函数。如下程序就是把函数max和函数min传递给getresult.根据程序传递的函数,getresult返回的值不同:#include #include #include int getresult(int a, int b, int (*compare)(int a ,int b)){ return (compare(a,b)原创 2010-10-11 21:06:00 · 315 阅读 · 0 评论 -
数组排序问题--快速排序法
快速排序法思想:把数组当作一个数值列表。排序开始时,它选择列表的中间值作为列表分隔符(list separator)。于是排序把列表分成两个列表,一个列表的值小于列表分隔符,另一个列表大于或者等于列表分隔符。然后排序在两个列表中递归调用自身。排序没调用自身一次。它就把元素分成更小的列表。快速排序法实现:#include int quick_sort(int arry[], in原创 2010-10-11 14:53:00 · 355 阅读 · 0 评论 -
数组排序问题--SHELL(希尔)排序法
SHELL排序法思想:对相隔指定距离(简称间距)的元素进行比较,一直到使用当前间隔进行比较的元素都按顺序排好为止。SHELL把间隔缩小一半,然后继续处理。当间隔最终变为1,并且不再出现变化时,SHELL排序也就完成了处理过程。SHELL排序实现:#include int print(int arry[],int size);int shell_sort(int arry[],原创 2010-10-11 09:07:00 · 906 阅读 · 0 评论 -
数组排序问题--选择排序法
选择排序法:选择排序法的思想:选择排序法选定一个元素作为开始(通常是第一个元素)。排序对整个数组进行搜索,一直找到最小的元素为止,排序把最小值放入第一个元素内,再选择第二个元素,然后搜索第二个小的元素。一次类推,最后得出排序结果。选择排序法实现:#include #include void print(int arry[], int size);void selection原创 2010-10-09 21:39:00 · 1229 阅读 · 0 评论 -
数组排序问题--冒泡排序法
冒泡排序法思想:假设用户是对数值从小到大进行排序,冒泡排序遍历数组中的值,进行比较,并把最大的数值移到数组的顶端(就像气泡升到水面一样)。第一次迭代把数组的最大值移到数组的顶端。第二次迭代将数组的第二大值移到数组的次顶端,这样依次类推,最后得出结果。冒泡排序法实现:#include #include void bubble_sort(int arry[],int size);原创 2010-10-08 21:29:00 · 560 阅读 · 0 评论 -
对半查找算法思想及实现
对半查找思想: 在数组中查找一个数值的方法之一就是逐个搜索数组元素,当数组长度很小时这种顺序查找是可以接受的,但是要循环查找一个大数组时是很浪费时间的。如果程序已经对数据元素进行了由大到小或者是由小到大的排序时,就可以通过折半查找来定位数组中的元素。对半查找实现:下面代码实现的前提是数组元素是由小到大排序的数组。 int binary_search(int arry[],原创 2010-10-08 16:58:00 · 2363 阅读 · 0 评论 -
Sorting Algorithms--Heap Sort
We've already looked at several O(n^2) sorting algorithms, bubble sort and selection and insertion sort. Now we turn to faster sorting algorithms that can sort in time proportional to O(n*log(n)) in the average and best case time, a significant speedup, as转载 2010-10-11 16:04:00 · 418 阅读 · 0 评论 -
Sorting Algorithms--Merge Sort
Merge sort is the second guaranteed O(nlog(n)) sort we'll look at. Like heap sort, merge sort requires additional memory proportional to the size of the input for scratch space, but, unlike heap sort, merge sort is stable, meaning that "equal" elements are转载 2010-10-11 16:02:00 · 379 阅读 · 0 评论 -
Sorting Algorithms--Bubble sort
<br /><br />Sorting Algorithms<br /><br />Have an array you need to put in order? Keeping business records and want to sort them by ID number or last name of client? Then you'll need a sorting algorithm. To understand the more complex and efficient sorting转载 2010-10-11 16:09:00 · 305 阅读 · 0 评论 -
Sorting Algorithms--Selection sort & Insertion Sort
Selection sortSelection sort is the most conceptually simple of all the sorting algorithms. It works by selecting the smallest (or largest, if you want to sort from big to small) element of the array and placing it at the head of the array. Then the proces转载 2010-10-11 16:08:00 · 425 阅读 · 0 评论 -
Sorting Algorithms Compared
<br />Sorting algorithms are an important part of managing data. At Cprogramming.com, we offer tutorials for understanding the most important and common sorting techniques. Each algorithm has particular strengths and weaknesses and in many cases the best t转载 2010-10-11 16:13:00 · 336 阅读 · 0 评论 -
单链表的基本操作
程序代码:#include #include #include using namespace std;//定义链表节点typedef int DataType;typedef struct node{ DataType data; struct node *link;}LinkedNode,*LinkList;//初始化链表LinkList Init_List(原创 2010-10-15 19:27:00 · 310 阅读 · 0 评论