云题海 - 专业文章范例文档资料分享平台

当前位置:首页 > 数据结构实验1

数据结构实验1

  • 62 次阅读
  • 3 次下载
  • 2025/5/24 10:37:41

}

5:

#include #include

typedef struct tagDataList {

int CreatDataList(int data) { }

int Up_InsertData(int data) //对于升序序列的插入 {

if(pstFirstNode -> data >= data)

pstCurrentNode -> data = data; pstCurrentNode -> pstNextNode = NULL;

//初始化

DataList *pstCurrentNode = malloc(sizeof(DataList)); //开辟空间 DataList *pstTmpNode = NULL; DataList *pstPreNode = NULL;

//初始化

//初始化

DataList *pstCurrentNode pstCurrentNode -> data if (pstFirstNode == NULL) { }

else { }

pstLastNode = pstCurrentNode; return 0;

//移动末尾指针

pstLastNode -> pstNextNode = pstCurrentNode; //不是空表加入表尾 pstFirstNode = pstCurrentNode;

= malloc(sizeof(DataList)); = data;

//赋值 //赋值

//开辟空间

DataList *pstFirstNode = NULL; DataList *pstLastNode = NULL;

int data;

struct tagDataList *pstNextNode;

//数据链表

}DataList;

pstCurrentNode -> pstNextNode = NULL;

//判断链表是否为空,空就把节点加入头指针

//对于要插入的数跟链表中的头指针指向的数据比较 }

int Down_InsertData(int data) //对于降序序列的插入 {

if(pstLastNode -> data >= data) //跟头指针比较 {

pstCurrentNode -> data = data; pstCurrentNode -> pstNextNode = NULL;

DataList *pstCurrentNode = malloc(sizeof(DataList)); DataList *pstTmpNode = NULL; { }

else if(pstLastNode -> data <= data) { } else

//跟中间数据比较 {

pstPreNode = pstFirstNode;

pstTmpNode = pstPreNode -> pstNextNode; while(pstTmpNode) {

if(pstTmpNode -> data >= data) {

pstLastNode -> pstNextNode = pstCurrentNode; pstLastNode = pstCurrentNode;

pstCurrentNode -> pstNextNode = pstFirstNode; pstFirstNode = pstCurrentNode;

//对于要插入的数跟链表中的尾指针指向的数据比较

//如果要插入的数据大于当前指针指向的数据,上一指针的 //Next指向要插入的指针 } return 0;

}

}

pstPreNode = pstPreNode -> pstNextNode; //往下移动 pstTmpNode = pstTmpNode -> pstNextNode;

pstPreNode -> pstNextNode = pstCurrentNode; pstCurrentNode -> pstNextNode = pstTmpNode; break;

DataList *pstPreNode = NULL;

}

}

pstLastNode -> pstNextNode = pstCurrentNode; pstLastNode = pstCurrentNode;

//跟尾指针比较

else if(pstFirstNode -> data <= data ) { } else { }

pstPreNode = pstFirstNode;

pstCurrentNode -> pstNextNode = pstFirstNode; pstFirstNode = pstCurrentNode;

//中间数据变焦

pstTmpNode = pstPreNode -> pstNextNode; while(pstTmpNode) { }

if(pstTmpNode -> data <= data && pstPreNode -> data >= data) { }

pstPreNode = pstPreNode -> pstNextNode; pstTmpNode = pstTmpNode -> pstNextNode;

pstPreNode -> pstNextNode = pstCurrentNode; pstCurrentNode -> pstNextNode = pstTmpNode; break;

//要插入的数据大于下一指针。小于上一指针

return 0; int main() {

printf(\输入-1退出有序序列的输入\\n\); printf(\请输入有序序列:\\n\); while(1) {

scanf(\,&nSign_Data); if(nSign_Data != -1) //创建链表 { }

CreatDataList(nSign_Data);

int nSign_Data = 0; int nInsertData; int nSelect = 0;

DataList *pstCurrentNode;

}

}

else

{ //当输入-1时,退出链表的创建 }

break;

printf(\请输入要插入的数据 : \); scanf(\, &nInsertData);

nSelect = pstFirstNode -> data - pstLastNode -> data; ///选择升序的插入还是降序的插入 if(nSelect < 0) { } else { }

pstCurrentNode = pstFirstNode; while(pstCurrentNode) { }

printf(\); return 0;

printf(\, pstCurrentNode -> data);

pstCurrentNode = pstCurrentNode -> pstNextNode; Down_InsertData(nInsertData); Up_InsertData(nInsertData);

搜索更多关于: 数据结构实验1 的文档
  • 收藏
  • 违规举报
  • 版权认领
下载文档10.00 元 加入VIP免费下载
推荐下载
本文作者:...

共分享92篇相关文档

文档简介:

} 5: #include #include typedef struct tagDataList { int CreatDataList(int data) { } int Up_InsertData(int data) //对于升序序列的插入 { if(pstFirstNode -> data >= data) pstCurrentNode -> data = data; pstCurrentNode -> pstNextNode = NULL;

× 游客快捷下载通道(下载后可以自由复制和排版)
单篇付费下载
限时特价:10 元/份 原价:20元
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219
Copyright © 云题海 All Rights Reserved. 苏ICP备16052595号-3 网站地图 客服QQ:370150219 邮箱:370150219@qq.com