新手上路第一天————菜鸟的心得之双向循环链表
来源:互联网 发布:凌云光技术待遇 知乎 编辑:程序博客网 时间:2024/06/06 09:04
每天学习,每天有收获。链表编程有一种定头指针的方式特别有用。
程序:查看mp3文件夹中,文件名,按1,下一个文件名,按2,上一个文件名
#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <dirent.h>#include <string.h>DIR *dir;struct dirent *ptr;struct mp3{ char name[10]; struct mp3 *next; struct mp3 *prior;};struct mp3 *head;struct mp3 *ps;void creat_list(){ head=(struct mp3*)malloc(sizeof(struct mp3)); head->next=head; head->prior=head;}void in_mp3(){ struct mp3 *q=head; struct mp3 *p; while((ptr=readdir(dir))!=NULL) { p=(struct mp3*)malloc(sizeof(struct mp3)); if(strcmp((ptr->d_name),".")==0||strcmp((ptr->d_name),"..")==0) { continue; } strcpy(p->name,ptr->d_name);q->next=p;p->prior=q;q=p;printf("q:%s\n",q->name); } head->prior=q; q->next=head; closedir(dir);}void display_mp3(){ struct mp3 *p=head; printf("name:"); while((p->next)!=head) { if(p==head) { p=p->next; } printf("%s",p->name); p=p->next; } printf("\n");}void re_mp3(int ch){ switch(ch) { case 0: ps=ps->next; if(ps==head) { ps=ps->next; } printf("now is:%s\n",ps->name); break;case 1: ps=ps->prior; if(ps==head) { ps=ps->prior; } printf("now is:%s\n",ps->name); break;default: printf("input error!\n"); break; } }int main(){ int ch; dir=opendir("mp3"); creat_list(); in_mp3(); //display_mp3(); ps=head->next; printf("now is:%s\n",ps->name); printf(">>>>>>>>>>0 is the next,1 is the prior<<<<<<<<<<\n"); while(1) { printf("please input:"); scanf("%d",&ch); re_mp3(ch); } return 0;}
- 新手上路第一天————菜鸟的心得之双向循环链表
- 新手上路第一天————菜鸟的心得之单链表(循环链表)
- 新手上路第一天————菜鸟的心得之单链表
- 新手上路————菜鸟程序错误总结
- C++新手上路第一天
- 数据结构之——循环双向链表的实现
- 一个文科女的计算机菜鸟的进阶之路——第一天
- 菜鸟学习FPGA第一天——疯狂的软件
- 图像处理——新手上路感悟
- 新手上路——Ubuntu系统配置安装
- 新手上路——hello world!
- 大话数据-—线性表之循环/双向链表
- 关于第一天学习JAVA的心得,菜鸟心得,勿喷
- 【菜鸟的成长之路】android游戏开发学习历程——记录每天的学习内容之【第一天】
- MATLAB——第一天 循环,函数
- 【链表】双向链表——双向循环链表
- 一个Android应用开发菜鸟的成长之路——工作第一天:解决了java.lang.NoClassDefFoundError问题
- C语言基础—数据结构之单向循环链表和双向循环链表
- linux core 文件的产生及gdb调试
- oiv7.0 --配置
- 函数返回局部变量问题
- 实习第4天
- 类加载器的委托机制学习笔记
- 新手上路第一天————菜鸟的心得之双向循环链表
- 不错的内网管理软件
- (function($){...})(jQuery)是什么意思
- lua 类继承和实现
- arm芯片中的浮点运算(一)
- 开关的第三态——系
- 一些离散的C++笔记
- 认识一下硬盘主引导扇区(ZT)
- Android下Affinities和Task