#include<stdio.h>
#include"stdlib.h" struct student
{
int data;
struct student *pnext;
};
struct students
{
struct students *prev;
int data;
struct students *pnext;
};
struct student *create(int dat); //单链表创造一个节点。
struct students *shuangcreate(int dat); //双链表创造一个节点。 void insert_head(struct student* pH,struct student* news);//单链表头插入
void insert_head_shuang(struct students* pH,struct students* news);//双链表头插入
void insert_tail_shuang(struct students* pH,struct students* news);//尾插入
int main()
{
struct student *ph=create();
struct students *phs=shuangcreate(); insert_head(ph,create());
insert_head(ph,create()); insert_head_shuang(phs,shuangcreate());
insert_head_shuang(phs,shuangcreate());
insert_head_shuang(phs,shuangcreate()); /*
insert_tail_shuang(phs,shuangcreate(1)); //尾插入
insert_tail_shuang(phs,shuangcreate(2)); printf("%d.\n",ph->data);
printf("%d.\n",ph->pnext->data);
printf("%d.\n",ph->pnext->pnext->data);
*/
printf("%d.\n",phs->data);
printf("%d.\n",phs->pnext->data);
printf("%d.\n",phs->pnext->pnext->data);
printf("%d.\n",phs->pnext->pnext->pnext->data); return ;
} struct student *create(int dat) //单链表创造一个节点。
{
struct student *p=(struct student*)malloc(sizeof(struct student));
if(NULL==p)
{
return NULL;
printf("节点分配失败");
}
p->data=dat;
p->pnext=NULL;
return p;
} struct students *shuangcreate(int dat) //双链表创造一个节点。
{
struct students *p=(struct students*)malloc(sizeof(struct students));
if(NULL==p)
{
return NULL;
printf("双链表节点分配失败");
}
p->data=dat;
p->pnext=NULL;
p->prev=NULL;
return p;
}
void insert_head(struct student* pH,struct student* news)
{
news->pnext=pH->pnext;
pH->pnext=news;
}
void insert_tail_shuang(struct students* pH,struct students* news) //双链表的尾插入
{
struct students* ph=pH;
while(NULL!=ph->pnext)
{
ph=ph->pnext;
printf("a\n");
}
ph->pnext=news;
news->prev=ph;
}
//画出双链表的节点链接情况
void insert_head_shuang(struct students* pH,struct students* news) //双链表的头插入
{
struct students* p=pH;
news->pnext=p->pnext;
if(p->pnext!=NULL) //考虑到只有一个头结点的情况。这里很重要 当第一次的时候p->pnext=NULL;
p->pnext->prev=news;
p->pnext=news;
news->prev=p;
}

接下来将会补齐单链表和双链表节点的 遍历 、逆序、和 删除 ;暂且放到这里,

最新文章

  1. 当PHP引擎试图实例化一个未知类的操作
  2. 通过命令行安装Android app
  3. SVN全量备份+增量备份脚本
  4. 自定义文件上传的按钮的样式css+js
  5. java Spring 基于注解的配置(一)
  6. SuperSocket入门(五)-常用协议实现模版及FixedSizeReceiveFilter示例
  7. tp框架基础知识
  8. APP的线程安全
  9. java语法部分一些小问题
  10. 运维yum搭建zabbix
  11. python中的__new__与__init__,新式类和经典类(2.x)
  12. [OpenCV]直线拟合
  13. MVC中常用的跳转方法
  14. H.264 SVC
  15. Java设计模式六大原则
  16. Django之URL控制器(路由层)
  17. ZeroTier One
  18. Slickflow.NET 开源工作流引擎高级开发(一) -- 流程外部事件的调用和变量存储实现
  19. 【js+jquery】通用、简单的JS 提示框
  20. 20145307陈俊达《网络对抗》Exp2 后门原理与实践

热门文章

  1. java-Enumeration,单向队列Queue及双向队列Deque等容器简单使用
  2. java泛型-泛型类,泛型接口,常用形式
  3. 使用ethtool显示硬件PHY信息
  4. 总结:当静态路由和BGP同时存在时路由优选BGP的两种方法
  5. SQL Server非域(跨域)环境下镜像(Mirror)的搭建步骤及注意事项
  6. js 学习之路8:for循环
  7. centos简单的后台运行
  8. 批处理基础知识-EXIT
  9. 解决topjui中工具栏按钮删除刷新从属表
  10. Linux上修改主机名