首页 > 其他分享 >实验2

实验2

时间:2024-10-12 21:11:34浏览次数:1  
标签:Lc LList next pc pa 实验 LNode

#include<stdio.h>
#include<malloc.h>

#define SIZE 100
#define INCREMENT_SIZE 10

#define TRUE 1
#define FALSE -1
#define OK 1
#define ERROR -1

typedef int Status;
typedef int ElemType;

typedef struct LNode
{
ElemType data;
struct LNode *next;
}LNode,*LList;

Status create(LList *L,int n)
{
*L = (LNode*)malloc(sizeof(LNode));
(*L)->next = NULL;
LNode *p=*L;
for(int i=1;i<=n;i++)
{
ElemType t;
scanf("%d",&t);
p->next=(LNode*)malloc(sizeof(LNode));
p->next->data=t;
p=p->next;
}
p->next = NULL;
return OK;
}

Status MergeList_L(LList La,LList Lb,LList *Lc)
{
LNode *pa=La->next;
LNode *pb=Lb->next;
*Lc = (LNode*)malloc(sizeof(LNode));
(*Lc)->next = NULL;
LNode *pc=*Lc;
while(pa&&pb)
{
if(pa->data <= pb->data)
{
pc->next = pa;
pa = pa->next;
pc = pc->next;
}
else
{
pc->next = pb;
pb = pb->next;
pc = pc->next;
}
}
if(pa)
{
pc->next = pa;
}
else
{
pc->next = pb;
}
return OK;
}

Status Purge(LList *L)
{
LNode *p=(*L)->next;
while(p->next)
{
LNode *q=p;
if(q->data!=q->next->data)
{
p=p->next;
}
else
{
q=q->next;
p->next=q->next;
free(q);
}
}
}

Status Print(LList L){
LNode* p = L->next;
while(p){
printf("%d ",p->data);
p = p->next;
}
printf("\n");
return OK;
}

int main()
{
LList La, Lb, Lc;
create(&La,5);
create(&Lb,6);
MergeList_L(La,Lb, &Lc);
Purge(&Lc);
Print(Lc);
return 0;
}

标签:Lc,LList,next,pc,pa,实验,LNode
From: https://www.cnblogs.com/JUVBUFFON/p/18461497

相关文章

  • 实验项目3 自定义路由转换器
    实验目的了解Django处理HTTP请求的流程。掌握路由转换器的用法。掌握如何定义和使用自定义路由转换器。实验内容操作1 创建Django项目chapter02(先进入之前创建的虚拟环境(python3.7、有Django))操作2 在项目chapter02中创建应用app01(应用需要激活应用并分配根路由、创建子......
  • 实验1
    任务1:task1.cpp1//现代C++标准库、算法库体验2//本例用到以下内容:3//1.字符串string,动态数组容器类vector、迭代器4//2.算法库:反转元素次序、旋转元素5//3.函数模板、const引用作为形参67#include<iostream>8#include<string>......
  • 实验2
    task.1#include<stdio.h>#include<stdio.h>#include<time.h>#defineN5#defineN1397#defineN2476#defineN321intmain(){intcnt;intrandom_major,random_no;srand(time(NULL));cnt=0;while(c......
  • 实验一 现代C++编程初体验
    case1://现代C++标准库、算法库体验//本例用到以下内容://1.字符串string,动态数组容器类vector、迭代器//2.算法库:反转元素次序、旋转元素//3.函数模板、const引用作为形参#include<iostream>#include<string>#include<vector>#include<algorithm>usi......
  • 实验1 现代C++编程初体验
    实验1现代C++编程初体验 task1:1//现代C++标准库、算法库体验2//本例用到以下内容:3//1.字符串string,动态数组容器类vector、迭代器4//2.算法库:反转元素次序、旋转元素5//3.函数模板、const引用作为形参6#include<iostream>7#include<strin......
  • 实验1 现代C++基础编程
    task1实验代码:#include<iostream>#include<string>#include<vector>#include<algorithm>usingnamespacestd;//声明//模板函数声明template<typenameT>voidoutput(constT&c);//普通函数声明voidtest1();voidtest2();voidtest3......
  • 《DNK210使用指南 -CanMV版 V1.0》第二十九章 音频录制实验
    第二十九章音频录制实验1)实验平台:正点原子DNK210开发板2)章节摘自【正点原子】DNK210使用指南-CanMV版V1.03)购买链接:https://detail.tmall.com/item.htm?&id=7828013987504)全套实验源码+手册+视频下载地址:http://www.openedv.com/docs/boards/k210/ATK-DNK210.html5)正点原......
  • 实验二
    任务一:#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1397//11班第一位学生的尾号#defineN2476//12班最后一位学生的尾号#defineN321//奇安信班一共21人intmain(){intcnt;intrandom_major,random_......
  • 实验1现代c++编程初体验
    test1:源代码:1#include<iostream>2#include<string>3#include<vector>4#include<algorithm>5usingnamespacestd;6template<typenameT>7voidoutput(constT&c);8voidtest1();9voidtest2();10voidtest3......
  • 实验2
    任务1源代码1#include<stdio.h>2#include<stdlib.h>3#include<time.h>45#defineN56#defineN13977#defineN24768#defineN321910intmain(){11intcnt;12intrandom_major,random_no;1314srand(t......