05 2012 档案

二分法插入排序
摘要:#include "stdio.h"#include "malloc.h"typedef int KeyType;typedef int DataType;typedef struct { //排序码字段 KeyType key; //记录的其他字段 DataType info;}RecordNode;typedef struct{ int n; RecordNode * record;}SortObject;void binSort(SortObject * pvector){ int i,j,left,right,middle; Record... 阅读全文

posted @ 2012-05-17 22:41 yucong 阅读(391) 评论(0) 推荐(0)

直接插入排序算法
摘要:代码分析:直接插入排序算法的平均移动次数与平均比较次数同级,都是O(n²),所以,直接插入排序的平均时间复杂度为T(n)=O(n²)。算法中引入了一个附加的记录空间temp,因此辅助空间为S(n)=O(1).直接插入排序是稳定的。#include "stdio.h"#include "malloc.h"typedef int KeyType;typedef int DataType;typedef struct { //排序码字段 KeyType key; //记录的其他字段 DataType info;}RecordNode;typ 阅读全文

posted @ 2012-05-17 21:34 yucong 阅读(371) 评论(0) 推荐(0)

Huffman算法-二叉树的应用
摘要:假设有一组实数,现在要构造一颗以Wi为权的m个外部结点的扩充二叉树,使得带权的外部路径长度WPL最小。满足这一要求的扩充二叉树就称为Huffman数或最优二叉树。声明:#include<stdio.h>#include<malloc.h>typedef struct node{ int data; struct node *lchild,*rchild,*next;}hufnode;typedef hufnode *linkhuf;/****************************************************//* huffman树 *//* 阅读全文

posted @ 2012-05-14 12:05 yucong 阅读(341) 评论(0) 推荐(0)

农夫过河问题-队列的应用
摘要:要模拟农夫过河问题,首先需要选择一个对问题中每个角色的位置进行描述的方法。一个很方便的办法是用四位二进制数顺序分别表示农夫,狼,白菜,和羊的位置。例如,用0表示农夫或者弄东西在河的南岸,1表示在河的北岸。因此,整数5(其二进制表示为1001)表示农夫和白菜在河的南岸,而狼和羊在北岸。这时农夫不在,因此狼可以把羊吃掉,所以是一种不安全的状态。问题的初始状态是整数0,;而问题的终结状态是整数15.用整数location表示上述方法描述的状态,可以用下面的四个函数从上述状态中得到每个觉得所在的位置的代码。函数返回值为1表示所考察的人或物在河的北岸,否则在河的南岸。队列的初始化:#include &q 阅读全文

posted @ 2012-05-13 10:10 yucong 阅读(3456) 评论(0) 推荐(0)

队列的实现-链表
摘要:声明:#include "stdio.h"#include "stdlib.h"typedef int DataType;struct Node;typedef struct Node *PNode;struct Node { DataType info; PNode link;};struct LinkQueue{ PNode f; PNode r;};typedef struct LinkQueue *PLinkQueue;//创建一个空队PLinkQueue createEmptyQueue_link(void){ PLinkQueue plqu; 阅读全文

posted @ 2012-05-12 22:56 yucong 阅读(369) 评论(0) 推荐(0)

队列的实现-顺序表
摘要:声明:#include "stdio.h"#include "stdlib.h"typedef int DataType;//队头f指出实队头元素所的位置,队尾r指出实队尾元素所的位置的下一个位置struct SeqQueue { int MAXNUM; int f,r; DataType *q;};typedef struct SeqQueue * PSeqQueue;//创建一个空队PSeqQueue createEmptyQueue_seq(int m){ PSeqQueue paqu=(PSeqQueue)malloc(sizeof(struct 阅读全文

posted @ 2012-05-12 21:05 yucong 阅读(408) 评论(0) 推荐(0)

迷宫问题的解决-栈的应用
摘要:声明和栈的声明一样:#include "stdio.h"#include "stdlib.h"typedef struct { int x,y,d;} DataType;struct SeqStack { int MAXNUM; //t<MAXNUM,指示栈顶位置,而不是元素个数; int t; DataType *s;};//顺序栈类型的指针类型typedef struct SeqStack * PSeqStack;//创建空栈PSeqStack createEmptyStack_seq(int m){ PSeqStack pStack=(PSe 阅读全文

posted @ 2012-05-12 12:51 yucong 阅读(472) 评论(0) 推荐(0)

栈的实现-链表
摘要:声明:#include "stdio.h"#include "stdlib.h"//单链表结点struct Node;//指向结点的指针类型typedef struct Node *PNode;typedef int DataType;struct Node { DataType info; PNode link;};//链接栈类型定义struct LinkStack { //指向栈顶结点 PNode top;};//链接栈类型的指针类型typedef struct LinkStack * PLinkStack;//创建一个空链栈PLinkStack c 阅读全文

posted @ 2012-05-11 11:13 yucong 阅读(188) 评论(0) 推荐(0)

栈的实现-顺序表
摘要:声明:#include "stdio.h"#include "stdlib.h"typedef int DataType;struct SeqStack { int MAXNUM; //t<MAXNUM,指示栈顶位置,而不是元素个数; int t; DataType *s;};//顺序栈类型的指针类型typedef struct SeqStack * PSeqStack;//创建空栈PSeqStack createEmptyStack_seq(int m){ PSeqStack pStack=(PSeqStack)malloc(sizeof(str 阅读全文

posted @ 2012-05-11 10:22 yucong 阅读(231) 评论(0) 推荐(0)

无回溯匹配模式
摘要:#include "stdio.h"#include "stdlib.h"struct SeqString { int MAXNUM; int n; char *c;};typedef struct SeqString * PSeqString;//创建空顺序串PSeqString createNullStr_Seq(int m){ PSeqString pstr=(PSeqString)malloc(sizeof(struct SeqString)); if(pstr!=NULL) { pstr->c=(char *)malloc(sizeo.. 阅读全文

posted @ 2012-05-08 23:46 yucong 阅读(562) 评论(0) 推荐(2)

朴素模式的匹配算法-顺序
摘要:声明:#include "stdio.h"#include "stdlib.h"struct SeqString { int MAXNUM; int n; char *c;};typedef struct SeqString * PSeqString;//创建空顺序串PSeqString createNullStr_Seq(int m){ PSeqString pstr=(PSeqString)malloc(sizeof(struct SeqString)); if(pstr!=NULL) { pstr->c=(char *)malloc(si.. 阅读全文

posted @ 2012-05-08 20:38 yucong 阅读(280) 评论(0) 推荐(0)

链表的应用1_josephus问题
摘要:声明:#include "stdio.h"#include "stdlib.h"#define FALSE 0#define TRUE 1typedef int DataType;struct Node;//单链表的结点类型typedef struct Node *PNode;//结点指针类型//单链表结点结构struct Node { DataType info; PNode link;};typedef struct Node *LinkList;typedef LinkList *PLinkList;2.初始化链表//用1,2,……,n为*pcli 阅读全文

posted @ 2012-05-08 15:01 yucong 阅读(225) 评论(0) 推荐(0)

顺序表的应用1--josephus问题
摘要:题目:设有n个人围坐在一个圆桌周围,现从第s个人开始报数,数到第m的人出列,然后从出列的下一个人重新开始报数,数到第m的人又出列……如此反复直到所有的人全部出列为止。Josephus问题是:对于任意给定的n,s和m ,求出按出列次序得到的n个人员的序列思路:采用顺序表模拟。可以用整数i来代替n(i),将初始序列改写成一个整数的序列1,2,3,……,n,并把它们存储在一个palist所指顺序表中,当s<=n时,第s个人放在palist->element[s-1]之中,因此第一个报数出列的应该是下标为s-1+m-1对n取模后的元素,如果这个下标为i ,出列工作只要将palist-> 阅读全文

posted @ 2012-05-03 16:43 yucong 阅读(587) 评论(0) 推荐(0)

链表的实现
摘要:1.声明如下#include "stdio.h"#include "stdlib.h"typedef int DataType; struct Node;//单链表结点类型typedef struct Node * PNode;//结点指针类型//单链表结点结构struct Node { DataType info; PNode link; };typedef struct Node * LinkList;2.//创建一个空链表LinkList createNullLinkList(){ LinkList list=(LinkList)malloc(si 阅读全文

posted @ 2012-05-02 23:35 yucong 阅读(207) 评论(0) 推荐(0)

顺序表的实现
摘要:声明:#include <stdio.h>#include "stdlib.h"typedef int DataType;1.构造一个机构体//创建空顺序表PSeqList createNullList_seq(int m){ PSeqList palist=(PSeqList)malloc(sizeof(struct SeqList)); if (palist!=NULL) { palist->element=(DataType *)malloc(sizeof(DataType) * m); if(palist->element) ... 阅读全文

posted @ 2012-05-02 00:20 yucong 阅读(385) 评论(0) 推荐(0)

导航