c 哈希学习
来源:互联网 发布:ubuntu cpuz 编辑:程序博客网 时间:2024/05/16 13:51
//
// main.c
// 1
//
// Created by cclyy on 14-7-19.
// Copyright (c) 2014年 cclyy. All rights reserved.
//
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
struct _word
{
int type;//1 ming 2 dong 3 xingrong
char word[64];
struct _word *ptNext;
};
typedef struct _word Word;
//new 1
Word *total_pw[100] = {NULL };
Word *pw =NULL;
void add (int t ,char *w)
{
Word *p1 = malloc(sizeof(Word));
strcpy(p1->word, w);
p1->type = t;
p1->ptNext =NULL;
//new 2
int hash_index = t % 100;
pw = total_pw[hash_index];
if (pw == NULL) {
pw = p1 ;
//new 3
total_pw[hash_index] = pw;
}
else
{
Word *ptmp = pw;
while(1)
{
if (ptmp->ptNext ==NULL) {
break;
}
ptmp = ptmp->ptNext;
}
ptmp->ptNext = p1;
}
}
void print()
{
//new 4
int i = 0;
for(i = 0; i <100; i ++)
{
//new 4 end
Word *ppp = NULL;
//new 5
ppp=total_pw[i];
//new 5 end
while (1) {
if (ppp == NULL) {
break;
}
printf("%d%s\n",ppp->type,ppp->word);
ppp = ppp->ptNext;
}
}
}
int main(int argc,const char * argv[]) {
int n = 0;
while (1) {
if (n == 30) {
break;
}
n++;
add(n, "a");
}
print();
return 0;
}
- c 哈希学习
- C学习
- C++学习
- c ++ 学习
- 学习C
- c学习
- 学习C#!
- 学习C
- c学习
- c学习
- 学习C
- 学习C
- 学习C++
- C学习
- c学习
- 【C/C++】学习导论
- C/C++____vector___学习
- C++C 学习
- UILabel 高度问题
- ubuntu cd 命令使用
- hdu 2157 How many ways??
- qt多目录比如包含自己编译的库
- C语言---结构体指针
- c 哈希学习
- oracle 主键删除,联合主键的创建
- AFNetWorking2.0
- 星际争霸2编辑器的初接触
- android 百度音乐搜索地址
- Java 将自定义的对象作为HashMap的key
- c 基础学习
- poj 1067 取石子游戏
- C预处理指令