基于ACM平台的编程训练(数据结构)

自学数据结构也有一段时日了,虽然推的比较慢但我一直是坚持把一块内容完全搞明白才去推下一块内容。正好有同学马上面临数据结构的期末考,我找他要了他们数据结构的期中考试上机模拟题,自己试做了一下。只做出来前四题,第五题实在是结构体太多太绕,我没有什么好的思路,暂时先搁置一会儿吧。

题目后面是我的个人题解

第一题(5分)

(1)编写一个将数组元素逆序打印的递归函数。

(2)编写main函数,输入N个整数,将其存入到一个数组中,并调用(1)中的函数,将元素逆序输出。

Example:

从键盘读入:5,7,1,4,6

输出为:6,4,1,7,5

#include <stdio.h>

#include <stdlib.h>

void InversePrint(int a[], int n)

{

/***补全函数***/

}

int main()

{

    int i;

    int a[5];

    for(i=0;i<5;i++){

       scanf("%d", &a[i]);

   

    }

    InversePrint(a,5);

     

}

第二题(5+5+10=20分)

/*

用带头结点的单链表存储一帧数据,计算该帧数据的累加值作为校验码,并将其附加在数据帧尾部

**************************************************

Please input the length of frame:

5

Please input the element of frame one by one:

9 3 8 4 1

The frame is: 1 4 8 3 9

The length of the frame is: 5

The checksum added is: 25

The length of the frame with added checksum is: 6

The frame with added checksum is: 1 4 8 3 9 25

**************************************************

Please input the length of frame:

0

The frame is:

The length of the frame is: 0

*/

#include "stdio.h"   

#include "stdlib.h"  

#define OK 1

#define ERROR 0

#define MAXSIZE 20

typedef int Status;

typedef int ElemType;

typedef struct Node

{

    ElemType data;

    struct Node *next;

}Node;

typedef struct Node *LinkList;

//==========================

//打印单链表

//==========================

void ListTraverse(LinkList L)

{

    LinkList p=L->next;

    while(p)

    {

        printf("%d ", p->data);

        p=p->next;

    }

    printf("\n");

}

//=======================================

//初始化单链表

//=======================================

Status InitList(LinkList *L)

{

/***补全函数***/

}

int ListLength(LinkList L)

{

    int i=0;

    LinkList p=L->next;

    while(p)                       

    {

        i++;

        p=p->next;

    }

    return i;

}

Status GetElem(LinkList L, int i, ElemType *e)

{

/***补全函数***/

}

Status ListInsert(LinkList *L, int i, ElemType e)

{

    int j;

    LinkList p,s;

    p = *L;  

    j = 1;

    while (p && j < i)

    {

       p = p->next;

       j=j+1;

    }

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

U2yyy

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值