数额结构(6.1~6.8)

news/2024/7/5 2:59:13

6-1链表的插入算法

题目:
在这里插入图片描述
在这里插入图片描述在这里插入图片描述

代码

int InsertPost_link(LinkList llist,DataType x,DataType y)
{
    LinkList m=llist->next;
    LinkList n;
    while(m->data!=x)
    {
        m=m->next;4
        if(m==NULL)
        {
            printf("not exist data %d\n",x);
            return 0;
        }
    }
    n=(LinkList)malloc(sizeof(struct Node));
    if(n!=NULL)
    {
        n->data=y;
        n->next=m->next;
        m->next=n;
        return 0;
    }
}

6-2链表的删除算法

在这里插入图片描述在这里插入图片描述
在这里插入图片描述
在这里插入图片描述代码

void DelNode_Link(LinkList head, DataType deldata)
{
    PNode p=head->next;
    PNode beforeP=head;
    while(p!=NULL)
    {
        if(p->data==deldata)
        {
            beforeP->next=p->next;
            free(p);
            return 0;
        }
        else
        {
            beforeP=p;
            p=p->next;
        }
    }
    printf("not exist %d\n",deldata);
}

6-3移动链表中的最大值到尾部

在这里插入图片描述在这里插入图片描述在这里插入图片描述

void  MoveMaxToTail(LinkList head)
{
    PNode pmax=NULL,p=NULL,pre=NULL,end=NULL;
    pmax=head->next;
    p=head->next->next;
    while(p)
    {
        if(p->data>pmax->data)
        {
            pmax=p;
        }
        p=p->next;
    }
    if(pmax->next==NULL)
    {
        return 1;
    }
    else
    {
        p=head;
        while(p)
        {
            if(p->next==pmax)
            {
                pre=p;
            }
            if(p->next==NULL)
            {
                end=p;
            }
            p=p->next;
        }
        pre->next=pmax->next;
        pmax->next=end->next;
        end->next=pmax;
    } 
    return 0;
}

6-4合并两个递增有序的单循环链表

在这里插入图片描述在这里插入图片描述在这里插入图片描述

PNode mergeNDeduplicateList(PNode tail1, PNode tail2)
{
    int temp;
    PNode pre,q;
    LinkList head=tail1->next->next;
    tail1->next->next=tail2->next->next;
    tail2->next->next=NULL;
    for(pre=head;pre->next!=NULL;pre=pre->next)
    {
        for(q=pre->next;q!=NULL;q=q->next)
        {
            if(pre->data>q->data)
            {
                temp=pre->data;
                pre->data=q->data;
                q->data=temp;
            }
        }
    }
    pre=head;
    q=pre->next;
    while(q)
    {
        if(pre->data==q->data)
        {
            if(q==tail2->next)
            {
                tail2->next=pre;
                pre->next=NULL;
            }
            else
            {
                pre->next=q->next;
                free(q);
                q=pre->next;
            }
        }
        else
        {
            pre=q;
            q=q->next;
        }
    }
    tail2->next->next=head;
    return tail2;
}

6-5链表中奇偶结点的移动

在这里插入图片描述
在这里插入图片描述在这里插入图片描述

PNode Move_Odd_Even(LinkList tail)
{
    PNode head=tail->next,pre=head->next,q=pre->next;
    PNode pre1,head1=(PNode)malloc(sizeof(struct Node));
    PNode pre2,head2=(PNode)malloc(sizeof(struct Node));
    pre1=head1;
    pre2=head2;
    while(q!=head->next)
    {
        if(pre->data%2==0)
        {
            pre->next=pre1->next;
            pre1->next=pre;
            pre1=pre;
        }
        else
        {
            pre->next=pre2;
            pre2->next=pre;
            pre2=pre;
        }
    pre=q;
    q=q->next;
    }
head1=head1->next;
pre2->next=head1;
pre1->next=head2;
return pre1;
}

6-6循环队列入队出队

在这里插入图片描述

在这里插入图片描述
在这里插入图片描述

void EnQueue_seq(SeqQueue squeue, DataType x)
{
    if((squeue->r+1)%squeue->Max==squeue->f)
    {
        printf("It is FULL Queue!");
    }
    else
    {
        squeue->elem[squeue->r]=x;
        squeue->r=(squeue->r+1)%(squeue->Max);
    }
}

void DeQueue_seq(SeqQueue squeue)
{
    if(squeue->f==squeue->r)
    {
        printf("It is empty queue!");
    }
    else
    {
        squeue->f=(squeue->f+1)%(squeue->Max);
    }
}

6-7 进制转换(10->16)

在这里插入图片描述在这里插入图片描述
在这里插入图片描述

void Push_seq(SeqStack sstack ,DataType x)
{
    if(sstack->top>=(sstack->MAX-1))
    {
        printf("overflow!\n");
    }
    else
    {
        sstack->top++;
        sstack->elem[sstack->top]=x;
    }
}
void Hexconversion(SeqStack sstack,int n)
{
    while(n)
    {
        int tmp=n%16;
        switch(tmp)
        {
                case 10:tmp='A';break;
                case 11:tmp='B';break;
                case 12:tmp='C';break;
                case 13:tmp='D';break;
                case 14:tmp='E';break;
                case 15:tmp='F';break;
        }
        Push_seq(sstack,tmp);
        n=n/16;
    }
    while(!IsNullStack_seq(sstack))
    {
        n=Top_seq(sstack);
        if(n<10)
        {
            printf("%d",n);
        }
        else
        {
            printf("%c",n);
        }
        Pop_seq(sstack);
    }
    
}

6-8 递归建立和层次遍历二叉树

我先说一下,这道题我没做出来,但是代码我敲了
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

BinTree CreateBinTree_NRecursion()
{
    LinkQueue queue=SetNullQueue_Link();
    BinTreeNode *s, *p,*Bt;
    char ch;
    int count=-1;
    ch=getchar();
    Bt=NULL;
    while(ch!='#')
    {
        s=NULL;
        if(ch!='@')
        {
            s=(BinTreeNode*)malloc(sizeof(BinTreeNode));
            s->data=ch;
            s->leftchild=s->rightchild=NULL;
        }
        EnQueue_link(queue,s);
            count++;
        if(count==0)
        {
            Bt=s;
        }
        else
        {
            p=FrontQueue_link(queue);
            if(s!=NULL&&p!=NULL)
            { if(count%2==1)
            {
             p->leftchild=s;
            }
            else
            {
                p->rightchild=s;
            }
             
            }
            if(count%2==0)
                DeQueue_link(queue);
         }
        ch=getchar();
        }
    }
     return Bt;
}

void LevelOrder(BinTree bt)
{
    BinTree p;
    LinkQueue queue=SetNullQueue_Link();
    if(bt==NULL)return;
    p=bt;
    EnQueue_link(queue,bt);
    while(!IsNullQueue_Link(queue))
    {
        p=FrontQueue_link(queue);
        DeQueue_link(queue);
        printf("%c",p->data);
        if(p->leftchild!=NULL)
            EnQueue_link(queue ,p->leftchild);
        if(p->rightchild!=NULL)
            EnQueue_link(queue,p->rightchild);
    }
}

http://lihuaxi.xjx100.cn/news/1570296.html

相关文章

代码随想录Day43 | 1049.最后一块石头的重量II | 494. 目标和 | 474. 一和零

1049. 最后一块石头的重量 II class Solution { public:int lastStoneWeightII(vector<int>& stones) {vector<int> f(30010,0);int sumaccumulate(stones.begin(),stones.end(),0);int target sum/2;for(int i0;i<stones.size();i){for(int jtarget;j>…

java 从字符串中 输出连续的整数

java 从字符串中 输出连续的整数 //编写程序&#xff0c;从键盘输入一个字符串&#xff0c;内有数字和非数字字符 // 如xy12ab93?5789$,连续的数字为一个整数。 // 例如&#xff1a;字符串中有3个整数&#xff1a;12 93 5786.统计整数个数&#xff0c;并依次输出 import java…

【系统架构】软件可靠性基础知识

导读&#xff1a;本文整理关于软件可靠性基础知识构建系统架构知识体系。完整和扎实的系统架构知识体系是作为架构设计的理论支撑&#xff0c;基于大量项目实践经验基础上&#xff0c;不断加深理论体系的理解&#xff0c;从而能够创造新解决系统相关问题。 目录 1、软件可靠性…

Spring面试题19:说一说Spring注解?什么是基于Java的Spring注解配置?什么是基于注解的容器配置?

该文章专注于面试,面试只要回答关键点即可,不需要对框架有非常深入的回答,如果你想应付面试,是足够了,抓住关键点 面试官:说一说Spring注解 Spring注解是一种在Spring框架中使用的特殊标记,用于在应用程序中声明特定的配置、行为或功能。注解可以应用于类、方法、字段…

Android handlerThread并发了解

Android开发中如何实现并发&#xff0c;参考HandlerThread代码 核心是由synchronized 配合 wait、notifyall进行处理并发 HandlerThread.java public class HandlerThread extends Thread {//优先级int mPriority;int mTid -1;Looper mLooper;private Nullable Handler mHa…

虚拟机安装 centos

title: 虚拟机安装 centos createTime: 2020-12-13 12:00:27 updateTime: 2020-12-13 12:00:27 categories: linux tags: 虚拟机安装 centos 路线图 主机(宿主机) —> centos --> docker --> docker 镜像 --> docker 容器 — docker 服务 1.前期准备 一台 主机 或…

C++项目 Boost搜索引擎

选取boost库官网中的一个网页作为根目录&#xff0c;用它来建立索引。用户在搜索引擎首页搜索&#xff0c;搜索关键字在服务端&#xff08;searcher)进行分词&#xff0c;查找index&#xff08;供系统进行查找索引&#xff09;。 使用单例模式&#xff0c;只有一个index对象。…

软件测试笔试

作者&#xff1a;爱塔居 专栏&#xff1a;软件测试 文章简介&#xff1a;记录了我在笔试、面试过程中遇见的一些小问题 1.软件的生命周期&#xff1a;需求分析、计划、设计、编码、测试、运行维护 2.软件测试的生命周期&#xff1a;需求分析、测试计划、测试设计/开发、测试执…