数据结构之链表
来源:互联网 发布:从使用者角度 云计算 编辑:程序博客网 时间:2024/05/22 00:27
#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>
typedef struct lnode
{
int data;
struct lnode *next;
}LNODE,*Linklist;
//创建链表,插入,删除,逆序(通过插入完成),合并。
LNODE *linklist_creat(LNODE *l,int n)
{
LNODE *head=(LNODE *)malloc(sizeof(LNODE *));
head->next=NULL;
LNODE *p,*q;
int i=1;
while(i<=n)
{
p=(LNODE *)malloc(sizeof(LNODE *));
printf("please enter the %d data/n",i);
scanf("%d",&p->data);
p->next=NULL;
if(head->next==NULL) head->next=p;//注意开始节点的问题。
else
q->next=p;
q=p;
i++;
}
return (head);
}
LNODE *linklist_reverse_creat(LNODE *l,int n)//逆序输入N个值到链表。
{
LNODE *head=(LNODE *)malloc(sizeof(LNODE *));
head->next=NULL;
LNODE *p,*q;
int i=1;
while(i<=n)
{
p=(LNODE *)malloc(sizeof(LNODE *));
p->next=NULL;
printf("please enter the %d num /n",i);
scanf("%d",&p->data);
p->next=head->next;//插入法进行逆序 关键句。
head->next=p;
i++;
}
return(head);
}
LNODE *linklist_insert(LNODE *l,int i,int e)//在I元素后插入
{
LNODE *p,*q;
p=l;
int j=0;
while(j==i)
{
p=p->next;
j++;
}
q=(LNODE *)malloc(sizeof(LNODE *));
q->data=e;
q->next=p->next;
p->next=q;
return(l);
}
LNODE *linklist_del(LNODE *l,int i,int &e)
{
return l;
}
void linklist_travel(LNODE *l)
{
LNODE *p;
p=l->next;
int i=1;
while(p)
{
printf("the %d num is %d /n",i,p->data);
p=p->next;
i++;
}
}
LNODE *linklist_reverse(LNODE *l)
{
LNODE *head,*p,*q;
p=l->next;
head=(LNODE *)malloc(sizeof(LNODE *));
head->next=NULL;
while(p!=NULL)
{
l->next=p->next;
p->next=head->next;//插入关键句
head->next=p;
p=l->next;
}
return(head);
}
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 数据结构之链表
- 游戏软件比企业软件复杂
- Class.forName神秘吗
- 仅会算法就做企业软件吗
- 单件模式(Singleton Pattern)
- GoF模式打开的新境界
- 数据结构之链表
- C++里的通用算法
- 非模式思维的惩罚
- 获取有关按平均 CPU 时间排在最前面的五个查询的信息.
- 【白皮书】SnapArchiving - Oracle历史数据归档与查询管理软件
- 构造arm-linux交叉编译工具链(Tool Chain)
- Ruby的Integer数据类型
- DSG证券基金行业本地异地容灾备份查询一体化方案(西部证券)
- 了解电子邮件:E-Mail从入门到精通