摘要:#include<stdlib.h>#include<stdio.h>typedef struct list{int data;struct list*next;} List;List* insert_list_last();List*reverse(List*head);int main(){List*head;List*p;head=insert_list_last();p=head->next;while(p){printf("%d\n",p->data);p=p->next;}printf("affter reve
阅读全文
摘要:#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;
阅读全文
摘要:归并排序的前提是:归并前两个数组是有序的。归并排序的思路是先分成两半使用归并排序,然后比较大小,从小到大复制到一个零时数组中去;如果比较后,一方有剩余,那么将剩下的复制到临时数组,最后将排序好的数组拷贝回原数组。归并排序的时间复杂度是: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[]
阅读全文
摘要:这种快速排序的思路是:首先以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_
阅读全文
摘要:快速排序的思路是:首先拿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
阅读全文
摘要:插入排序的思路是:新插入的数与比它前面的数进行比较,如果新插入的数比它前面的数小,那么比它前面的数后移;否则,就找到了新插入的数的位置插入排序的时间复杂度是: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
阅读全文
摘要:选择排序的思路是:先假定一个数十最小的,后面的数与之比较,如果比它小,那么记录下标,替换最小值;依次往复,则排序完毕选择排序的时间复杂度是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
阅读全文
摘要:冒泡排序的思路是将最大的数或者最小的数移到最右端或者最左端第一层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
阅读全文
摘要:#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
阅读全文
摘要:#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()
阅读全文
摘要://链表有序插入和删除最重要的是预判,就是判断下一个是否满足要求,因为如果只是判断当前,那么当你找到要操作的节点时,已经过了指向该节点的指针//删除的时候注意释放空间#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
阅读全文
摘要://以让数组得到充分的利用,所以采用循环数组//队列为空,则front==rear 如果队列满了,(rear+1)%N=front 数组中最后一个元素未利用 是为了区分空和满的情况 #include<stdio.h>#include<stdlib.h>#define N 100typedef struct queue{int store[N];int front;int rear;}Queue;void init_queue(Queue*q) {q->front=q->rear=0;}void inqueue(Queue*q,int data){if((q-
阅读全文
摘要:插入队列时,注意判断队列是否为空出队列时,注意判断:1 队列是否为空 2 是否是最后一个元素出队列 3 正常出队列#include<stdio.h>#include<stdlib.h>typedef struct list{int data;struct list*next;}List;typedef struct queue{List*front;List*rear;}Queue;void init_queue(Queue*q){q->front=q->rear=NULL;}void inqueue(Queue *q,int data){List*newn
阅读全文
摘要:#include<stdio.h>#include<stdlib.h>typedef struct list{int data;struct list*next;}List;typedef struct stack{List*top;}Stack;Stack*A;Stack*B;void init_stack(Stack*s){s->top=NULL;}void push_stack(Stack*s,int data){List*newnode=(List*)malloc(sizeof(List));newnode->data=data;newnode-&g
阅读全文
摘要:#include<stdio.h>#include<stdlib.h>#define N 100typedef struct stack{char store[N];int top;}Stack;void init_stack(Stack *s);void push_stack(Stack *s,char data);char pop_stack(Stack *s);int match(char x, char y);int main(){char *table;int flag=1;Stack*s=(Stack*)malloc(sizeof(Stack));init_
阅读全文
摘要:#include<stdio.h>#include<stdlib.h>struct node{int data;struct node*next;};struct Binode{int data;struct Binode*next;struct Binode*prev;};struct Binode*func(struct node*head);int main(){//新建衣蛾单链表struct node*head=NULL;struct node*temp;struct node*newnode;struct Binode*Bihead=NULL;struct B
阅读全文
摘要:今天去面试,笔试部分出了三道题,第一题是文件的打包;第二个是两个大数相乘;第三题是单链表改成循环链表第三题算是做出来了,但是前面两题没有想法。尽管才做出一题,但是还是参加了第二轮面试。考官第一问:进程和线程的区别,答对了第二问:线程中栈和堆的区别我说不知道,不过现在想来老师讲过,malloc开辟的空间在堆区;临时变量在栈区第三问:考官还算好,再问那么堆和栈,临时变量在那个区我脑子一片糊涂,马上说堆区,考官说今天的面试结束。就这样被咔嚓掉了。我总结我今天失败的原因:1回答问题没有三思而后行,回答不经脑子,其实这个问题答案我是知道的2 不懂装懂,这也许是考官最痛恨的,也许我说不知道会比我说在堆区更
阅读全文
摘要:链表实现栈#include<stdio.h>#include<stdlib.h>typedef struct list{int data;struct list *next;}List;typedef struct stack{List*top;}Stack;void init_stack(Stack*s){s->top=NULL;}void push_stack(Stack *s,int data){List *newnode=(List*)malloc(sizeof(List));newnode->data=data;newnode->next=s
阅读全文
摘要:一.C语言中参数传递传递都是传值,都是对数值的拷贝的一个副本二.递归与迭代用递归能够解决的问题,一定能用迭代(循环)解决(1)递归的特点:思路简单,运算较慢使用递归,关键是找到递归的出口递归由于不停地出栈和入栈,并且前一次的结果并没有保留,下一次还得计算,所以效率是比较低的改进递归算法的一种方法是将前面的计算结果进行保留,提高效率(2)迭代就是用循环解决问题,迭代算法的效率是很高的三.有关数组的理解(1)数组名永远是数组中第一个元素的地址(2)*和[]是一样的(3)二维数组也可以看做是一维数组,只不过数组中每个元素又是一个数组四.数组小练int array[10];int *ap=array+
阅读全文
摘要:一.运算符的优先级算数运算符>移位运算符>关系运算符>逻辑运算符>赋值运算符,的运算等级是最低的value=value|1<<x;这里<<比|等级高,先执行移位,在执行|,最后赋值二.在赋值操作时要考虑的是类型转换比如int型转化为char型时要截短三.关于++和--a++是先取a的值,然后a再自增++a是先自增a的值,然后在取自增后a的值--一样的原理
阅读全文
摘要:一.关于define 跟typedef的理解:define 是用一个名字来代替另一个名字typedef是对一个已经存在的类型 定义一个别名(1)#define ptr-int int *ptr-int a,b;是定义了一个int *类型指针变量a,定义一个int型变量b他只是简单的替代,在预编译时替代(2)typedef int * ptr-int;ptr-int a,b;是定义了一个int*的两个指针变量a和b二.对C语言中数据类型的理解C语言对不同类型的数据用不同类型的变量来进行存储C语言数据类型可以分为4种,有整型,实型,指针,聚合类型,前面三种是基本的类型整型有short,int,lo
阅读全文