qingcheng奕  

2013年6月5日

摘要: C/C++内存存储问题是笔试中必须掌握的。先看下面的程序:#include <stdio.h>#include "string.h"#include "malloc.h"void Swap(int a,int b){ int temp; temp=a; a=b; b=temp;}int Get_Int(int a){ int i=1+a; return i;}char* Get_Memory0(){ char* p=(char*)malloc(sizeof(char)* 20); strcpy(p,"hello world" 阅读全文
posted @ 2013-06-05 23:29 qingcheng奕 阅读(523) 评论(0) 推荐(0) 编辑

2013年6月2日

摘要: //图 存顶点 存边 存顶点数 存边数//用临接表存储#include <iostream>typedef struct bian{ int j; struct bian* next;};//每一个点存储自己的边表,每个点最多10条边typedef struct dian{ char a; bian* bianbiao ;};//图存储边数,点数,以及点的集合,最多20个点typedef struct graph{ int n,e; struct dian dianbiao[20];};struct graph mygraph;int visited[20]... 阅读全文
posted @ 2013-06-02 11:09 qingcheng奕 阅读(242) 评论(1) 推荐(0) 编辑
 
摘要: 1 广搜存在问题!!!!! 2 //建立一棵树,然后做深搜,广搜 3 #include <iostream> 4 5 typedef struct node{ 6 int data; 7 struct node* left; 8 struct node* right; 9 }; 10 11 struct node* new_node(int _data) 12 { 13 node* temp = (node*)malloc(sizeof(node)); 14 if(!temp) 15 { 16 printf... 阅读全文
posted @ 2013-06-02 11:08 qingcheng奕 阅读(226) 评论(0) 推荐(0) 编辑

2013年5月27日

摘要: 1 //哈希做查找 2 //建立一个哈希表,然后查找元素 3 #include <iostream> 4 const int tablelength = 15; 5 int maxtimes = 4; 6 int keynum = 13; //小于容量15的最大素数 7 int invalidedata = -1;//hash表中没有内容时每个单元初始化为-1 8 int fullflag = -2; //hash表满 9 int notfind = -3; 10 typedef struct node 11 { 12 int data; 13 /////... 阅读全文
posted @ 2013-05-27 12:41 qingcheng奕 阅读(227) 评论(0) 推荐(0) 编辑

2013年5月26日

摘要: 堆排序,先将数组中存入的数据实现小顶堆的性质,然后再进行一个个的输出排序。本来堆就是一个数组,是个一维的结构,用数组的下标进行标识。0就是堆的顶,然后把一个数组给维护成一个堆。堆的操作都是原地的。//堆做堆排序#include //交换两个数字void swap(int &a,int &b){ int t; t = a;a = b; b = t; return;}//对数组建堆void buildheap(int data[],int length,int root,int flag,int num){ if(flag ==1) //对于建完堆之后,排序的调用,需要把o... 阅读全文
posted @ 2013-05-26 22:21 qingcheng奕 阅读(197) 评论(0) 推荐(0) 编辑

2013年5月25日

摘要: //随机生成100个数,做插入排序,链表的练习随机生成100个数,做插入排序,链表的练习#include <iostream>#include <stdio.h>#include <stdlib.h>typedef struct node{ int data; struct node* next;};void insert(node * tnode,node* thead){ node *itr = thead; if(tnode->data <thead->data) { tnode->next = thead; thead = t 阅读全文
posted @ 2013-05-25 17:08 qingcheng奕 阅读(160) 评论(1) 推荐(0) 编辑
 
摘要: #include <iostream>const int SIZE = 101;typedef struct queue{ int front,rear; int data[SIZE];};void init(struct queue *_queue){ _queue->front = _queue->rear = 0;}bool isEmpty(struct queue *_queue){ return _queue->front ==_queue->rear;}bool isFull(struct queue *_queue){ return _queu 阅读全文
posted @ 2013-05-25 17:05 qingcheng奕 阅读(91) 评论(0) 推荐(0) 编辑
 
摘要: //zhan和队列,你就实现一个之后,插入1-100,然后取出1-100#include <iostream> typedef int datatype;#define SIZE 100typedef struct stack{ datatype data[100]; int head;}_stack;void init(struct stack *_stack){ for(int i = 0;i<100;i++) (*_stack).data[i] = 0; (*_stack).head = 0;}bool isEmpty(struct stack *_... 阅读全文
posted @ 2013-05-25 17:04 qingcheng奕 阅读(107) 评论(0) 推荐(0) 编辑

2013年5月22日

摘要: http://poj.org/problem?id=3750小孩报数问题好不容易写出了单链表版本,提交竟然out time limited。代码如下:#include <iostream>#include <string>using namespace std;typedef struct child{ char name[20]; struct child* next;};void child_delete(child* p){ child* _p = p->next; p->next = _p->next; free(_p);}int main() 阅读全文
posted @ 2013-05-22 08:57 qingcheng奕 阅读(401) 评论(0) 推荐(0) 编辑

2011年11月16日

摘要: 这个是用来清空cin缓冲区里面未读取的信息...例子: #include <iostream>using namespace std;int main () { char first, second; cout << "Please, enter a word: "; first=cin.get(); cin.sync(); cout << "Please, enter another word: "; second=cin.get(); cout << "The first word began 阅读全文
posted @ 2011-11-16 17:23 qingcheng奕 阅读(1895) 评论(0) 推荐(0) 编辑