
C/C++、数据结构与算法
yecats
姓名:黄闯 联系电话:13520472742
展开
-
非递归实现斐波那契数列
#include"stdio.h"main(){ int arr[10]; int i ; for(i=0;i<10;i++){ if(i==0||i==1){ arr[i]=1; } else{ arr[i]=0; } } for(i=2;i原创 2015-09-08 22:04:07 · 270 阅读 · 0 评论 -
单链表实现交差和
#define MAXSIZE 10#define ADDSIZE 5typedef int ElemType;typedef struct{ ElemType *elem; int length; int size;}SqList;#include "stdio.h"#include "malloc.h"#include"head.h"void Ini原创 2015-09-08 23:23:15 · 371 阅读 · 0 评论 -
前、中、后、序递归遍历二叉树以及非递归遍历
#include"stdio.h"#include"malloc.h"#include"LinkStack.c"typedef int ElemType;typedef struct BitNode{ ElemType data; struct BitNode *lchild,*rchild;}BitTree;//1、利用前序遍历递归创建二叉树BitTree *原创 2015-09-09 09:58:08 · 334 阅读 · 0 评论 -
结构体应用(2)
#include"stdio.h"struct vote{ int count; char name[10];}cand[4]={{0,"3"},{0,"4"},{0,"5"},{0,"6"}};main(){ int i,j,c_max=0,max_index=0; char cname[10]; printf("进入投票:\n"); fo原创 2015-09-08 22:51:16 · 403 阅读 · 0 评论 -
顺序队列
#include "stdio.h"#include #define MAXSIZE 10typedef int ElemType;typedef struct Node{ int front,rear; ElemType elem[MAXSIZE];}SqQueue;SqQueue * InitQueue(){ SqQueue *q; q=(SqQ原创 2015-09-09 09:25:01 · 274 阅读 · 0 评论 -
从文件中读取数据以及二分查找
#include"stdio.h"//从文件中读取内容main(){ FILE *fp; fp=fopen("f://1.txt","r"); if(fp==NULL){ printf("读取失败!"); }else{ while(feof(fp)!=-1){ char ch=fgetc(fp); putchar(ch); } fclose(fp); }}原创 2015-09-09 09:51:37 · 808 阅读 · 0 评论 -
快速排序
#include"stdio.h"void swap(int arr[],int low,int high){ int temp; temp = arr[low]; arr[low]=arr[high]; arr[high]=temp;}int partition(int arr[],int low,int high){ int point;原创 2015-09-09 09:59:28 · 339 阅读 · 0 评论 -
输入三个数字进行排序(冒泡原理)
void get2(int a,int b,int c){ int temp = 0; if(a<b){ temp=b; b=a; a=temp; } if(a<c){ temp=c; c=a; a=temp; }if(c<b){原创 2015-09-08 21:56:30 · 1026 阅读 · 0 评论 -
使用一维数组进行简单排序(冒泡法)
#include"stdio.h"main(){ int arr[4]; int i ,j; for(i=0;i<4;i++){ scanf("%d",&arr[i]); } for(i=0;i<4;i++){ int temp=0; for(j=i;j<4;j++){ if(arr原创 2015-09-08 22:08:12 · 1941 阅读 · 0 评论 -
输入三个数字使用指针进行排序(冒泡原理)
#include"stdio.h"//可以与上一篇文章进行对比,进一步掌握指针概念void sort(int *x,int *y,int *z){ int temp; if(*x>*y){ temp=*x; *x=*y; *y=temp; } if(*x>*z){ temp=*x;原创 2015-09-08 22:16:03 · 1462 阅读 · 0 评论 -
使用指针数组访问一维数组数据
#include"stdio.h"#include"math.h"main(){ int arr[10]={1,2,3,4,5,6,7,8,9,0},i; int *p[10]; for(i=0;i<10;i++){ p[i]=&arr[i]; } for(i = 0;i<10;i++){ printf("%4d",*p原创 2015-09-08 22:33:16 · 943 阅读 · 0 评论 -
结构体指针访问结构体数组
#include"stdio.h"struct student{ int code; char name[10]; char sex[3]; int age;}stu;main(){ struct student stus[4]; int i; struct student *s; for(i=0;i<4;i++){原创 2015-09-08 22:57:42 · 3044 阅读 · 0 评论 -
栈
#include "stdio.h"#include "malloc.h"#define MAXSIZE 100typedef int datatype;#define NULL 0typedef struct{ datatype stack[MAXSIZE]; int top;}seqstack;seqstack * InitStack(seqstack *s原创 2015-09-08 23:28:12 · 505 阅读 · 0 评论 -
顺序表
#include "stdio.h"#include "malloc.h"#define MAXSIZE 10#define ADDSIZE 5typedef int ElemType;typedef struct{ ElemType *elem; int length; int size;}SqList;void InitList(SqList *L){原创 2015-09-08 23:26:25 · 230 阅读 · 0 评论 -
中序式转后序式?(a+b)*(c+d)=>ab+cd+*
反之亦然!原创 2016-03-01 16:04:43 · 937 阅读 · 0 评论 -
后序式的计算程序?
#include#includevoid eval(char *);//double cal(double,char,double);//int main(void){ char input[100]; printf("输入后序运算式:"); scanf("%s",input); eval(input); return 0;}//计算后序式int eval(char *fi原创 2016-03-01 16:22:41 · 780 阅读 · 0 评论 -
结构体数组
#include"stdio.h"struct student{ int code; char name[10]; char sex[3]; int age;}stu;main(){ struct student stus[4]; int i; for(i=0;i<4;i++){ struct student s原创 2015-09-08 22:55:17 · 391 阅读 · 0 评论 -
链队列
#include"stdio.h"#include"malloc.h"typedef int ElemType;typedef struct QNode{ ElemType data; struct QNode *next;}LinkQueue;typedef struct PointerNode{ LinkQueue *front,*rear;}QueueP原创 2015-09-09 09:46:39 · 239 阅读 · 0 评论 -
字符数组应用
#include"stdio.h"#include"math.h"main(){ char *arr[3]={"fsd","fdsf","fere"}; int i; for(i=0;i<3;i++){ printf("arrary:%s\n",arr[i]);//存的每一个的值,首地址,自动依次读到最后,故为一个串 } for(i=0原创 2015-09-08 22:35:12 · 297 阅读 · 0 评论 -
使用指针遍历二维数组
#include"stdio.h"#include"math.h"main(){ /* int arr[10]= {1,2,3,4,5,6,7,8,9,10},i,j; int *p; p=arr; for(i=0;i<10;i++){ printf("%5d",*p++); }*/ /* int arr[3][原创 2015-09-08 22:30:14 · 971 阅读 · 0 评论 -
统计一字符串中个数最多的字符
#include"stdio.h"#include"string.h"//找出个数最多的字符main(){ char str[50],*p1,*p2,*max_p; int count=0,maxcount=0; gets(str); p1=str; for(p1;*p1!='\0';p1++){ count=0;原创 2015-09-08 22:40:44 · 487 阅读 · 0 评论 -
使用结构体实现学生信息管理系统
#include"stdio.h"#include"malloc.h"#define format "%d %s %s %d"struct student{ int code; char name[10]; char sex[3]; int age; struct student *next;};//初始化头节点struct student *原创 2015-09-08 22:59:31 · 6458 阅读 · 0 评论 -
选择排序
#include"stdio.h"void selectSort(int a[],int n){ int i,j,min_index; for(i=0;i<n-1;i++){ min_index = i;//固定索引 for(j=i+1;j<n;j++){ if(a[min_index]>a[j]){//交换索引原创 2015-09-08 23:14:25 · 312 阅读 · 0 评论 -
输入一个整数判断是否是回文
#includeusing namespace std;//输入一个整数判断是否是回文int main(){ int val; //存放待判断的数字,不超过10位数的回文数字 int m; int sum = 0; printf("请输入您需要判断的数字:\n"); scanf("%d",&val); m = val; while (m) { sum = sum*10 +原创 2015-09-08 21:30:16 · 1470 阅读 · 0 评论 -
冒泡排序算法以优化
#include"stdio.h"void sort(int arr[],int n){ int i ,j ,temp,f; for(i=0;i<n-1;i++){ f=1; for(j=0;j<n-1-i;j++){ if(arr[j]>arr[j+1]){ f=0;//排了就变零原创 2015-09-08 22:10:09 · 319 阅读 · 0 评论 -
函数指针
#include"stdio.h" void print(int x){ printf("%d ",x); }main(){ typedef void (*fu)(int x);//函数 重命名 fu f=&print;//or f=print;指向print函数 f(64000);}原创 2015-09-08 22:19:47 · 247 阅读 · 0 评论 -
链栈(头插法)
#include "stdio.h"#include "malloc.h"typedef int ElemType;typedef struct node{ ElemType data; struct node *next;}LinkStack;LinkStack * InitStack(){ LinkStack *s; s=(LinkStack *原创 2015-09-09 09:31:23 · 811 阅读 · 0 评论 -
递归实现猴子吃桃问题与兔子生产问题(斐波那契数列)
#include"stdio.h"//猴子吃桃问题int get(int n,int toal){ if(n==1){ return toal; } return get(n-1,(toal+1)*2);}//兔子生产问题int fb(int n,int a,int b){ int temp =0; temp = b; b=原创 2015-09-08 22:01:15 · 618 阅读 · 0 评论 -
简单二维数组转置问题
#include"stdio.h"void sort(int arr[],int n){ int i ,j ,temp,f; for(i=0;i<n-1;i++){ f=1; for(j=0;j<n-1-i;j++){ if(arr[j]>arr[j+1]){ f=0;//排了就变零原创 2015-09-08 22:13:21 · 787 阅读 · 0 评论 -
二级指针应用
#include"stdio.h"main(){ int arr[10]={1,2,3,4,45,5,6,7,7,12},i; int *p_arr[10]; int **p_p_arr; p_p_arr=p_arr; for(i=0;i<10;i++){ p_arr[i]=&arr[i]; } for(i=0;i<10;i原创 2015-09-08 22:41:47 · 490 阅读 · 0 评论 -
结构体应用(1)
#include"stdio.h"struct student{ int code; char name[10]; char sex[3]; int age;}stu;main(){ //struct student stu; printf("学号、姓名、性别、年龄:"); scanf("%d %s %s %d",&stu.code,s原创 2015-09-08 22:43:09 · 610 阅读 · 0 评论 -
结构体指针
#include"stdio.h"#error ""struct student{ int code; char name[10]; char sex[3]; int age;}stu;main(){ struct student *s; s=&stu; printf("学号、姓名、性别、年龄:"); scanf("%d %s原创 2015-09-08 22:54:17 · 201 阅读 · 0 评论 -
将一个字符串中的'\t'换成四个空格
//实现将一个字符串中的'\t'换成四个空格, '\t'个数不定。 #include "stdio.h"#define TOTAL_LEN 1024//是'\t'返回1int IsCharTab(char chData){ return (('\t' == chData) ? 1 : 0);}//当str = '/'并且 str+1 = 't',即 "/t"int IsStrTab(const c原创 2015-09-08 21:14:40 · 3124 阅读 · 0 评论 -
堆空间的开辟与释放
#include"stdio.h"#include"math.h"main(){ int size,i; int* base =NULL,* p; printf("输入大小;"); scanf("%d",&size); base = (int *)malloc(sizeof(int)*size);//堆,需要释放free() p=base;原创 2015-09-08 22:23:31 · 1099 阅读 · 0 评论 -
顺序队列
#include "stdio.h"#include #define MAXSIZE 10typedef int ElemType;typedef struct Node{ int front,rear; ElemType elem[MAXSIZE];}SqQueue;SqQueue * InitQueue(){ SqQueue *q; q=(SqQ原创 2016-06-08 09:29:31 · 499 阅读 · 0 评论