網(wǎng)站首頁 編程語言 正文
//合并兩個(gè)遞增有序的鏈表
#include
#include
typedef int ElemType;
typedef struct LNode{
ElemType data;
struct LNode *next;
}LNode,*LinkList;
//初始化單鏈表
void InitList(LinkList &L)
{
L = (LinkList)malloc(sizeof(LNode));
L->next = NULL;
}
//尾結(jié)點(diǎn)創(chuàng)建單鏈表
void createTailList(LinkList &L)
{
ElemType x;
LNode *p;
LNode *r=L;
scanf("%d",&x);
while(x!=9999)
{
p = (LNode*)malloc(sizeof(LNode));
p->data = x;
r->next = p;
r = p;
scanf("%d",&x);
}
r->next = NULL;
}
void combineList(LinkList &A,LinkList B)
{
LNode *pa = A->next;
LNode *pb = B->next;
LNode *r;
A->next = NULL;
r=A;
while(pa!=NULL && pb!=NULL)
{
if(pa->datadata)
{
r->next = pa;
r = r->next;
pa = pa->next;
}else{
r->next = pb;
r = r->next;
pb = pb->next;
}
}
if(pa!=NULL)
pb = pa;
while(pb!=NULL)
{
r->next = pb;
r = r->next;
pb = pb->next;
}
r->next = NULL;
}
//打印單鏈表
void printList(LinkList &L)
{
LNode *p=L->next;
while(p!=NULL)
{
printf("%d ",p->data);
p = p->next;
}
printf("\n");
}
void main()
{
LinkList LA,LB;
InitList(LA);
InitList(LB);
createTailList(LA);
createTailList(LB);
printf("A:");
printList(LA);
printf("B:");
printList(LB);
printf("A combine with B:");
combineList(LA,LB);
printList(LA);
}
?
原文鏈接:https://blog.csdn.net/qq_61706112/article/details/121859872
相關(guān)推薦
- 2022-06-18 Android使用廣播發(fā)送消息_Android
- 2022-03-27 Redis?使用?List?實(shí)現(xiàn)消息隊(duì)列的優(yōu)缺點(diǎn)_Redis
- 2022-04-01 17條提高工作效率的Python技巧分享_python
- 2022-07-07 Python筆記之a(chǎn)?=?[0]*x格式的含義及說明_python
- 2022-03-22 C語言寫一個(gè)散列表_C 語言
- 2022-12-08 Anaconda中pkgs文件夾及如何清空PKGS_相關(guān)技巧
- 2023-01-19 flask?post獲取前端請(qǐng)求參數(shù)的三種方式總結(jié)_python
- 2022-03-03 iview 在 Table 組件中,文字過長(zhǎng)用省略號(hào)代替,鼠標(biāo)放上去 Tooltip 文字提示
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支