⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 哈希表.txt

📁 数据结构学习用到的一些程序!!里面有二叉树相关的几个
💻 TXT
字号:
#include <stdio.h> 
#include <stdlib.h> 

typedef struct node{ 
int number; 
struct node *next; 
}Node; 

int main(void){ 
int i,first=1; 
Node *hash[1000]={NULL}; 
for(i=0;i<1000;i++){ 
int inp,fx; 
scanf("%d",&inp); 
fx=inp/10; 
if(hash[fx]==NULL){ 
hash[fx]=(Node *)malloc(sizeof(Node)); 
hash[fx]->number=inp; 
hash[fx]->next=NULL; 
}else if(hash[fx]->number>inp){ 
Node *temp; 
temp=(Node *)malloc(sizeof(Node)); 
temp->number=inp; 
temp->next=hash[fx]; 
hash[fx]=temp; 
}else{ 
Node *temp,*insert; 
for(temp=hash[fx]; temp->next!=NULL;temp=temp->next) 
if(temp->next->number>inp) 
break; 
insert=(Node *)malloc(sizeof(Node)); 
insert->number=inp; 
insert->next=temp->next; 
temp->next=insert; 
} 
} 

for(i=1;i<1000;i++){ 
Node *temp; 
for(temp=hash[i];temp!=NULL;temp=temp->next) 
if(first){ 
printf("%d",temp->number); 
first=0; 
}else 
printf(" %d",temp->number); 
} 
return 0; 
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -