![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
Andy-Action-Now
这个作者很懒,什么都没留下…
展开
-
双栈实现 队列
#include "stdafx.h"#include #include using namespace std;templateclass Queue_by_stack { public: Queue_by_stack(){}; ~Queue_by_stack(){}; void append_tail(const T& node); T delete_原创 2013-09-09 22:34:22 · 816 阅读 · 0 评论 -
将ip地址压缩到一个无符号整形中
#include #include /* * @brief 求N的指数 * @param matter in 底数 * @param exponent in 指数 */int pow(const int matter, const int exponent);/* * @brief 字符串转整形 * @param strVal in 字符串 * @param va原创 2014-12-14 20:39:46 · 1446 阅读 · 0 评论 -
链表逆序
typedef struct _LIST_{ int data; struct _LIST_ *next;}Node, *List;/** * @param brief 反转一个链表,递归方法 * @param head in out 链表头节点 * @return List 返回链表头节点 * */List reverse_list(List head){原创 2014-12-18 19:18:44 · 492 阅读 · 0 评论 -
将一个字符串中小于0的数字放到左边,大于0的数字放到右边
void sort_str(char* str){ char cTmp; int nlen = strlen(str); for (int i = 0; i < nlen; i++) { //not a number if (str[i] > 57 && str[i] < 48 && str[i] != '-') return; if (str[i] == '原创 2014-06-26 18:49:22 · 1632 阅读 · 0 评论 -
shell排序
void ShellSort(int a[], int n){ int i,j; int d = n; int itmp; while (d>= 1) { for ( i = d; i < n; i++) { if (a[i-d] > a[i]) { itmp = a[i]; j = i - d; do { a[j+d]原创 2013-11-18 16:41:56 · 726 阅读 · 0 评论 -
冒泡排序 优化
// BubbleSort.cpp : Defines the entry point for the console application.//#include "stdafx.h"void Swap(int &a, int &b){ int itmp; itmp = a; a = b; b = itmp;}void BubbleSort(int a[], int原创 2013-11-16 17:36:29 · 899 阅读 · 0 评论 -
快速排序算法
// math.cpp : Defines the entry point for the console application.//#include "stdafx.h"void Swap( int* ifirst, int* isecond ){ int itmp; if ( ifirst && isecond ) { itmp = *ifirst; *ifirs原创 2013-09-08 12:44:55 · 614 阅读 · 0 评论 -
C 语言面试题
1.gets()函数 问:请找出下面代码里的问题: 1.#include 2.int main(void) 3.{ 4. char buff[10]; 5. memset(buff,0,sizeof(buff)); 6. 7. gets(buff); 8. 9. printf("\n The buffer entered is [%s]\n",buff); 10. 1转载 2013-09-27 14:47:12 · 690 阅读 · 0 评论 -
单向链表的常见问题
单向链表的常见问题链表中的对象也是按线性顺序排列的,但与数组不同,数组的线性顺序是由数组的下标,再深层次说是由数组的内存结构限定的,而链表中的顺序则是由各对象中的指针决定的。声明一个单向链表如下:class SLink_ListNode{public: SLink_ListNode(int data,SLink_ListNode* pNext = NULL); ~S转载 2013-10-10 16:40:49 · 1012 阅读 · 0 评论 -
用户输入M,N值,从1至N开始顺序循环数数,每数到M输出该数值,直至全部输出
用户输入M,N值,从1至N开始顺序循环数数,每数到M输出该数值,直至全部输出。写出C程序。实现如下:单向链表// CircleLink.cpp : Defines the entry point for the console application.//#include "stdafx.h"#include typedef struct _STU{ int num; str原创 2013-10-09 19:02:06 · 1306 阅读 · 0 评论 -
常见算法集合
1. Factorial INT64 factorial( int n ){ if ( 0 == n ) { return 1; } else { return ( n * factorial( n - 1 ) ); }}/* test factorial */ INT64 tmp = factorial( 20 ); printf( "%lld\原创 2013-09-24 11:04:28 · 667 阅读 · 0 评论 -
位移 例子
int _tmain(int argc, _TCHAR* argv[]){ int result = 0; int sum = 0; int count = 0; for (int i = 1; i < 9; i++ ) { if ( i %3 == 0) { result = 0; sum = sum | result << count; count+原创 2013-10-08 08:21:30 · 1017 阅读 · 0 评论 -
The FOUR_QUEEN question solutions
#include "stdafx.h"#include #include #include static int count; /*count of queen solutions */int IsCorrect( int i , int j, int (*Q)[4] ){ int s, t; for ( s = i, t = 0; t < 4; t++ ) /* 行检查 *原创 2013-09-15 09:32:58 · 886 阅读 · 0 评论 -
Queue 链表
#include "stdafx.h"#include #include typedef char ElemType;typedef struct _QNode{ ElemType data; struct _QNode *next;}QNode, *QueuePtr;typedef struct { QueuePtr front; QueuePtr rear;}原创 2013-09-14 22:42:46 · 851 阅读 · 0 评论 -
砝码 碎片问题
#include "stdafx.h"#include int getWeight( int i, int j, int k, int s, int weight){ int x1, x2, x3, x4; for ( x1 = -1; x1 <= 1; x1++ ) for ( x2 = -1; x2 <= 1; x2++ ) for ( x3 = -1; x3 <=原创 2013-09-15 10:47:29 · 864 阅读 · 0 评论 -
栈 操作
#include #define STACK_INIT_SIZE 100#define STACKINCREMENT 100typedef int ElemType;typedef int status;typedef struct{ ElemType *base; ElemType *top; int stacksize;}sqStack;status Ini原创 2013-09-12 09:32:25 · 836 阅读 · 0 评论 -
动态数组
#include "stdafx.h"#include using namespace std;#define MAXSIZE 10typedef int ElemType ;typedef struct{ int *elem; int length; int listsize;} Sqlist;void InitSqlist( Sqlist *L ){ L->e原创 2013-09-11 20:31:49 · 762 阅读 · 0 评论 -
浮点数 与 16进制 相互转换
/* * @brief 浮点型 转换成 16进制 默认小端排列 * @param val in 浮点数 * @param hex out 16进制数 * @return */void float_to_hex(const float& val, char hex[4]){ const char *p = (char*)(&val); hex[0] = *((char*)p);原创 2014-12-14 21:09:46 · 7681 阅读 · 1 评论