文件检索(C循环双链表实现)
2012-07-13 09:10
281 查看
/********************************************************************************** 读取目录中的文件名,放到循环双链表中,按1查看前一个, 按2查看后一个,按3退出。 **********************************************************************************/ #include<stdio.h> #include<stdlib.h> #include<string.h> #include"unistd.h" #include"sys/types.h" #include"fcntl.h" #include"dirent.h" struct DuLNode { char num[100]; struct DuLNode *prior,*next; }; struct DuLNode *head=NULL; struct DuLNode *tmp=NULL; cre_list() //初始化 { head = (struct DuLNode *)malloc(sizeof(struct DuLNode)); head->prior = head; head->next = head; } add_DuLNode(char *num) //插入结点 { if(head->num == 0) { strcpy(head->num,num); } else { struct DuLNode *ptr = (struct DuLNode *)malloc(sizeof(struct DuLNode)); strcpy(ptr->num,num); ptr->next=head->next; head->next=ptr; ptr->prior=head; ptr->next->prior=ptr; } } display_DuLNode() //遍历链表 { struct DuLNode *p = head; do { printf("%s\n",p->num); p = p->next; }while(p!=head); } display_next_DuLNode() // { // struct DuLNode *p = head; tmp= tmp->next; printf("%s\n",tmp->num); } display_prior_DuLNode() // { //struct DuLNode *p = head; tmp= tmp->prior; printf("%s\n",tmp->num); } int main(int argc, char * argv[]) { int i=0; cre_list(); DIR *dp; struct dirent *dirp; if (argc != 2) { printf("Usage: ls directory_name"); } //打开指定的目录 if ((dp = opendir(argv[1])) == NULL) { printf("can't open %s\n", argv[1]); exit(1); } //遍历目录 while ((dirp = readdir(dp)) != NULL) { if(strcmp(dirp->d_name,".")==0 || strcmp(dirp->d_name,"..")==0) { continue; } add_DuLNode(dirp->d_name); } //关闭目录 closedir(dp); display_DuLNode(); tmp=head; while(1) { printf("1.prior 2.next 3.exit:"); scanf("%d",&i); switch(i) { case 1: { display_prior_DuLNode(); break; } case 2: { display_next_DuLNode(); break; } case 3: { return 0; } default: { continue; } } } return 0; }
相关文章推荐
- 循环双链表加目录IO实现简单的文件检索
- 编写一个程序实现循环双链表的各种基本运算(假设顺序表的元数基本类型为Char)
- Java简单递归实现检索文件
- shell脚本 for循环实现文件和目录遍历
- Halcon中循环读取文件的实现以及数字与字符的转换
- 【c++版数据结构】之循环双链表的实现(带头结点以及尾节点)
- 如何使用C\C++实现文件的检索 ?
- 模板实现顺序表和循环双链表
- JAVA---实现检索指定路径下的所有的下属文件夹和文件
- VC下利用多线程实现文件的快速检索
- c语言之————有头循环双链表实现队列存储
- VC下利用多线程实现文件的快速检索
- Python基于正则表达式实现检查文件内容的方法【文件检索】
- Halcon中循环读取文件的实现以及数字与字符的转换
- java的File机制实现目录下的文件检索
- C语言实现非循环双链表节点的删除(带头结点尾结点)
- lecene.net实现pdf,doc,xls,ppt,htm,html等格式文件的检索
- 数据结构实现循环双链表
- Shell实现循环执行curl向Solr导入json文件
- 1.python实现循环执行目标目录下脚本文件