
C语言
文章平均质量分 71
sjyu_金色年华
这个作者很懒,什么都没留下…
展开
-
将M*N矩阵中0元素所在的行、列的元素全部置为0
将M*N矩阵中0元素所在的行、列的元素全部置为0解决这个问题可以有两种办法:1:借助于O(M*N)空间,对矩阵元素逐行或逐列修改2:借助于O(M+N)空间,对矩阵元素逐个检查是否要置为0 1:第一种方法//将M*N矩阵中0元素所在的行、列的元素全部置为0#include #define M 3#define N 4int main(){ int原创 2013-06-07 10:01:02 · 1647 阅读 · 0 评论 -
C语言中的scanf和printf函数的返回值问题
相信学习过C语言的人对这两个库函数再熟悉不过了,但是你是否真如你自己认为的那样对这两个函数了如指掌了呢?首先,先来看一个小小的例子:#include int main(){char s[100];int a,b;printf("%d\n",scanf("%s",s));printf("%d\n",scanf("%d%d",&a,&b));printf("%d\n原创 2013-11-18 10:30:31 · 1953 阅读 · 0 评论 -
联发科技一道笔试题目
读程序结果:#include #include int main(){ int n; char y[10] = "ntse"; char *x = y; n = strlen(x); printf("n=%d\n",n);//n=4 *x = x[n]; x++; printf("x=%s\n",x);//原创 2013-12-09 14:18:06 · 1899 阅读 · 1 评论 -
C/C++中 变量的存储位置
1、首先,讲下 “堆 heap” 和 “栈 stack” 的区别: 一个由 c/c++编译过的程序占用的内存分为一下几个部分 (1)、栈区 stack :由编译器自动分配释放,存放函数的参数值,局部变量的值等。这个栈的操作方式类似于数据结构中的栈。 (2)、堆区 heap :一般由程序员分配释放,若程序员不释放,程序结束时可能由OS回收,注意它与数据结构中的堆是两回事,分配转载 2013-12-09 15:11:30 · 699 阅读 · 0 评论 -
不用(+)运算符实现两个整数相加
采用位运算符实现: #include/* 不用(+)运算符实现两个整数相加 */int add_without_operater(int a, int b){ if(b == 0) /* 当没有产生进位时 */ return a; int sum; /* 不考虑进位,各位相原创 2013-12-09 14:00:51 · 1379 阅读 · 0 评论 -
斐波那契数列递归实现和非递归实现
#include //斐波那契数列递归实现int fibonacci_recurise(int n){ if(n == 1 || n == 2) return 1; else return fibonacci_recurise(n - 1) + fibonacci_recurise(n - 2);}//斐波那契数列原创 2013-12-09 13:56:04 · 797 阅读 · 0 评论 -
矩阵中的“马鞍点”,即满足该元素在所在行最小,在所在列最大
#include #define M 4#define N 4int main(){ int a[M][N]; int i, j, k, c, min; int flag = 0; for(i = 0; i < M; i++) for(j = 0; j < N; j++) scanf("%d",&a[i][j]原创 2013-12-09 14:08:10 · 6608 阅读 · 0 评论 -
C/C++中函数的传值调用、指针调用、引用调用问题
以swap函数来说明问题: #include #include void swap1(int a, int b){ int temp; temp=a; a=b; b=temp; printf("a=%d,b=%d\n",a,b);}void swap2(int *a, int *b){ int te原创 2013-12-10 16:45:03 · 947 阅读 · 0 评论 -
字符串处理函数
面试中面试官会经常让你现场写的程序主要集中在字符串处理函数的实现上:1、字符串的复制2、字符串的连接3、字符串的比较4、字符串的查找(查找一个字符串在另一字符串中的位置)5、字符串的转换(atoi函数、atof函数)前三个函数的实现都比较容易,但必须注意的一点是:一定要注意字符串结束标识符是否需要认为的添加到目的字符串中。字符串的查找,其实就是模式匹配,数据结构中降到K原创 2013-12-09 10:41:51 · 620 阅读 · 0 评论 -
C/C++之字符串操作
字符串操作包括:字符串的复制、字符串的连接、字符串的比较(1)字符串的复制/**字符串的复制,文件名:str_cpy.c*/#include void str_cpy1(char *d, char *s){ char *begin = d; while(*begin++ = *s++);}void str_cpy2(char *d, char *s){原创 2014-01-05 15:10:15 · 609 阅读 · 0 评论 -
C/C++查找之一(顺序查找、折半查找(二分查找))
进行查找算法,首先得明确数据的存储结构:顺序存储(数组)或链式存储(链表)对于顺序存储,可以有:顺序查找和折半查找(对于后者的前提是此顺序表是有序的);对于链式存储,只能进行顺序查找。1、顺序查找//顺序表的查找#include void search(int *data, int n, int t){ int i, num=0; for(i = 0原创 2013-08-20 14:32:15 · 4412 阅读 · 0 评论 -
如何求一组数的逆序数
/***求一组数的逆序数*方案一(1)对数组中的每个数计算逆序数,之后再加和,得出整个数组的逆序数,复杂度O(n^2)*方案二(2)借助归并排序的思想求解*/#include #include int compute1(int *begin, int *end){ int *p, *q; int sum1, sum = 0; for(p = begin;原创 2014-01-18 09:59:24 · 2163 阅读 · 0 评论 -
如何求由已知字符串产生的N个字符串的第M个字符串
/************************************************************************1、输入一个字符串(字符串个数为N)2、由已知字符串产生N-1个字符串,产生规则如下: 将第i个字母之前的所有i - 1个字母整体移到末尾3、加上原来的字符串总共N个,输出这N个字符串中最小的一个(字符串的大小按字典顺序排列)例如:“原创 2014-02-22 20:01:52 · 945 阅读 · 0 评论 -
如何求数组中的最大数和第二大数
/***求数组中第二大数:(1)先排序,再找第二大数,复杂度O(n^2)(2)设置两个变量分别存储最大数和第二大数,遍历数组更新两变量, 复杂度O(n)(3)考虑到效率问题,使用二分法并结合(2),复杂度O(log n)*/#include //函数声明void search1(int * , int , int * , int *);void search2(int * ,原创 2014-01-17 16:48:40 · 1402 阅读 · 0 评论 -
如何在DOS下编译C文件
原文地址:http://blog.chinaunix.net/uid-26432915-id-3337775.html如何在DOS下编译C源文件 系统是Windows 7 homebasic 安装工具是Microsoft Visual C++ 6.0我的VC按装在D盘 一个简单的C源文件#includes转载 2013-11-15 17:30:38 · 5582 阅读 · 0 评论 -
哈夫曼树的构造
哈夫曼树的特点:n个结点全为叶子结点,并且总共有2*n-1个结点,权值路径之和最小。#include #include #define max 100struct huffmantree{ int weight; struct huffmantree *lchild; struct huffmantree *rchild; struc原创 2013-08-28 00:15:37 · 1138 阅读 · 0 评论 -
C/C++ 排序之一(冒泡排序、选择排序、交换排序)
#include void bubble_sort(int *begin, int *end){ int *i, *j, *k; for(i = end; i >= begin; i --) for(j = begin; j + 1 <= end; j ++) if(*j > *(j + 1))原创 2013-08-19 19:33:58 · 1160 阅读 · 0 评论 -
C/C++ 排序之三(快速排序(递归))
快速排序(递归)#include int *parse(int *begin, int *end){ int temp = *begin;//存储第一个数 //寻找第一个数要分割的位置 while(begin < end) { while(begin < end && temp <= *end) end --;原创 2013-08-20 19:38:46 · 827 阅读 · 0 评论 -
C/C++排序之二(直接插入排序、 折半插入排序、归并排序(递归))
直接插入排序、 折半插入排序4、直接插入排序insertion_sort#include void insertion_sort(int *begin, int *end){ int *i, *j, temp; for(i = begin + 1; i <= end; i ++) { temp = *i; for原创 2013-08-19 21:17:11 · 1447 阅读 · 0 评论 -
C/C++排序之五(堆排序)
堆排序heap_sort#include void adjust_heap(int *begin, int *end, int index){ int temp = *(begin + index); int child = (index << 1) + 1; while(child <= end - begin) {原创 2013-08-21 21:50:33 · 664 阅读 · 0 评论 -
C/C++ 排序之四(计数排序)
计数排序counting sort#includevoid counting_sort( int a[], int n ){ int count = 0 ; int k = 0 ; while( k < n - 1) { for( int i = k + 1 ; i < n ; i++ ) {原创 2013-08-20 21:03:30 · 806 阅读 · 0 评论 -
二叉排序树的操作(建立、插入、删除和查找)
二叉排序树的建立、插入、删除和查找(删除待补充)#include #include typedef struct node{ int key; struct node *lchild,*rchild;}BSTNode;BSTNode *InsertBST(BSTNode *T, int key){ BSTNode *f, *p = T;原创 2013-08-22 15:55:41 · 5926 阅读 · 1 评论 -
C语言经典著作导读
本人不是卖书的,我也不会给出任何购书链接,只是给C语言学习者推荐一条学习的方向。如果你喜欢看电子书网上很多,如果你喜欢纸质那么就买吧,经典的书值得收藏,是对版权的尊重! 基础篇1.《写给大家看的C语言书(第2版)》原书名: Absolute Beginner's Guide to C (2nd Edition) 原出版社: Sams 作者: (美)G转载 2013-08-23 10:32:52 · 988 阅读 · 0 评论 -
C及C++运算符的优先级和结合性
C语言运算符的优先级和结合性,自上而下优先级逐次下降:PrecedenceOperatorDescriptionAssociativity1++ --Suffix/postfix increment and decrementLeft-to-right()Function call原创 2013-08-18 13:03:26 · 951 阅读 · 0 评论 -
二叉树前序序列、中序序列、后序序列互求
两种情况:1、已知前序序列和中序序列,求后序序列2、已知后序序列和中序序列,求前序序列//已知前序序列和中序序列,求后序序列#include void preorder_inorder_to_postorder(char *preorder, char *inorder, int length){ if(length > 0) {原创 2013-08-23 21:47:07 · 1929 阅读 · 0 评论 -
图的深度优先搜索(DFS)、广度优先搜索(BFS)
深度优先搜索(DFS)、广度优先搜索(BFS)图的邻接矩阵形式#include #include #include #define MAX 100typedef struct{ int edges[MAX][MAX]; //邻接矩阵 int n; //顶点数 int e;原创 2013-08-24 16:07:45 · 980 阅读 · 0 评论 -
比较两个数的大小,交换两个数的 方法总结
面试宝典中看到的,记录下来,与大家共勉1、比较两个数的大小/*比较两个数的大小,不要使用if判断*/#include #include int main(){ int a, b; printf("please input a and b:\n"); scanf("%d%d",&a,&b); //方法1 int max原创 2013-08-27 19:14:08 · 5508 阅读 · 0 评论 -
链表基本操作(建立、修改,插入、删除、打印)
#include #include struct list{ int data; struct list *next;};//头插法建立链表struct list *headcreate(){ struct list *head, *p; int N,i; head=NULL; printf("输入要建立的链表结点个数N=");原创 2013-08-17 16:19:46 · 780 阅读 · 0 评论 -
TIOBE Programming Community Index for August 2013
摘自:http://www.tiobe.com/index.php/content/paperinfo/tpci/index.htmlTIOBE Programming Community Index for August 2013August Headline: Search engine changes affect C and Objective-C most转载 2013-08-17 17:11:31 · 1140 阅读 · 0 评论 -
C 语言中的字符函数和字符串函数
ANSI C标准要求在使用字符函数时要包含头文件“ctype.h”,在使用字符串函数时要包含头文件“string.h”函数名函数原型功能返回 值包含文件isalnum 检查ch是否是英文字母或数字原创 2013-08-18 14:01:02 · 1225 阅读 · 0 评论 -
C语言中浮点数在内存中的存储格式
首先给出查阅资料的一些链接:首先来看两个例子:#include #include union stu{ int i; char c; float f;}a;int main(){ FILE *fp; fp=fopen("a.txt","w"); fprintf(fp,"%d\n",sizeof(char))原创 2013-12-26 13:45:12 · 2106 阅读 · 0 评论