数据结构实训——单词检索统计程序

  1. /***********************************************************  
    * 版权所有 (C)2016,WuHao 
    *  
    * 项目名称:单词检索统计程序  
    * 其它说明: 各个模块函数   
    * 作 者:    武昊  
    * 完成日期: 20161230  
    **********************************************************
    
    hao.h:
    /********************************************************* 
    * 版权所有 (C)2016,wuhao
    * 
    * 内容摘要:对各种参数进行初始化 
    * 文件名称:hao.h
    * 文件标识:hao.h
    * 其它说明:可以读取txt文件 
    * 当前版本: V8.0 
    * 作 者:  武昊 
    * 完成日期: 20161230
    * 
    ************************************************************/
    
    
    #include <stdio.h>
    #include <stdlib.h> 
    #include <string.h>  
    #define LIST_INIT_SIZE 500   /*线性表存储空间的初始分配量*/ 
    #define LISTINCREMENT 10     /*线性表存储空间的分配增量*/ 
    #define FILE_NAME_LEN 20        /*文件名长度*/ 
    #define WORD_LEN     20         /*单词长度*/ 
    #define MaxStrSize   256  
    #define llength 110          /*规定一行有110个字节*/ 
    #define MaxStr 258 
    #define WORD 21   
    typedef struct 
    {            
    	char ch[MaxStr];  /* ch是一个可容纳256个字符的字符数组 */           
    	int length;
    	
    } string; /* 定义顺序串类型 */ 
    typedef struct 
    {      
    	char word[WORD];          /*存储单词,不超过20个字符*/     
    	int count;                 /*单词出现的次数*/ 
    } elem_type;   
    typedef struct{      
    	elem_type *elem;           /*存储空间基址*/     
    	int length;                /*当前长度*/      
    	int listsize;              /*当前分配的存储容量*/ 
    } sqlist; 
    
    
    
    
    
    /********************************************************* 
    * 版权所有 (C)2016,wuhao
    * 
    * 文件名称:word.cpp
    * 文件标识:word.cpp
    * 内容摘要:单词检索
    * 其它说明:无 
    * 当前版本: V8.0 
    * 作 者:  武昊 
    * 完成日期: 20161230
    * 
    ************************************************************/
    
    
    
      #include"hao.h" 
     int sqlist_init(sqlist *sq, elem_type *et) 
    {      
    	sq->elem = et;     
    	sq->length = 0;     
    	return 0;} 
    /********************************************************* 
    * 功能描述:单词添加
    * 输入参数:变量i,j,结构体:sqlist,elem_type
    * 输出参数:无 
    * 返回值  :0
    * 其它说明:无 
    ************************************************************/ 
    
    int sqlist_add(sqlist *sq, elem_type *et, char *word) {      
    	int i;     
    	int j;      
    	for (i = 0; i < sq->length; i++)     
    	{      /*当前单词与加入的单词相同,直接统计,不做插入 */         
    		if (strcmp(et[i].word, word) == 0)         
    		{              
    			et[i].count++;            
    			return 0;         
    		}         
    		if (strcmp(et[i].word, word) > 0)        
    		
    		{              
    			break;        
    		}     
    	}      
    	if (sq->length == LIST_INIT_SIZE)     
    	{          printf("空间不足,单词[%s]插入失败\n", word);        
    	return 0;     
    	}       
    	for (j = sq->length; j > i; j--)    
    	{         
    		memcpy(et+j, et+j-1, sizeof(elem_type)); 
    	}       
    	sq->length++;      
    	strcpy(et[i].word, word);     
    	et[i].count = 1;       
    	return 0; 
    }  
    /********************************************************* 
    * 功能描述:单词输出
    * 输入参数:变量i,j,结构体:sqlist,elem_type
    * 输出参数:无 
    * 返回值  :j
    * 其它说明
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值