2020/6/22

科目内容补充时间
数学第一章结束

介值定理、零点定理、最值定理的证明。通过所证结论构造函数,根据新函数的连续的区间,带入两端点所得函数判断。

3.设L为带头结点的单链表,编写算法实现从尾到头反向输出每个节点的值

void output_R(LinkList &L)
{
    if (L == NULL)//合法性判断
        return;//跳出
    if(L!=NULL)
        output_R(L->next);
    printf("%d", L->data);
}

4.试编写在带头结点的单链表L中删除一个最小值节点的高效算法(假设最小值节点是唯一的)

#include <malloc.h>
#include <stddef.h>
#include <stdio.h>
typedef struct LNode
{
    int data;
    struct LNode *next;
} LNode, *LinkList;

bool InitList(LinkList &L)
{
    L = NULL;
    return true;
}

LinkList List_TailInsert(LinkList &L)
{
    int x;
    L = (LNode *)malloc(sizeof(LNode));
    L->next = NULL;
    LNode *s, *r = L;
    scanf("%d", &x);
    while (x != 9999)
    {
        s = (LNode *)malloc(sizeof(LNode));
        s->data = x;
        r->next = s;
        r = s;
        scanf("%d", &x);
    }
    r->next = NULL;
    return L;
}
void printlist(LinkList L)
{
    LNode *t;
    t = L->next;
    while (t != NULL)
    {
        printf("%d", t->data);
        t = t->next;
    }
}
bool Delete_min(LinkList &L)
{
    int x = 0;
    LNode *p, *pre, *q;
    p = L->next;
    q = L;
    pre = L;
    if (L == NULL)
        return false;
    x = p->data;
    while (p != NULL)
    {
        if (x > p->data)
        {
            x = p->data;
            pre = q;
        }
        p = p->next;
        q = q->next;
    }
    q = pre->next;
    pre->next = q->next;
    free(q);
    return true;
}

int main(void)
{
    LNode *L;

    InitList(L);
    printf("shuruzifu:");
    List_TailInsert(L);
    printlist(L);
    printf("First one word is %d", L->next->data);
    printf("________");
    Delete_min(L);
    printlist(L);

    return 0;
}


试编写算法将带头结点的单链表就地逆置,所谓“就地”就是空间复杂度为 O ( 1 ) O(1) O(1)

#include <malloc.h>
#include <stddef.h>
#include <stdio.h>
typedef struct LNode
{
    int data;
    struct LNode *next;
} LNode, *LinkList;

bool InitList(LinkList &L)
{
    L = NULL;
    return true;
}

LinkList List_TailInsert(LinkList &L)
{
    int x;
    L = (LNode *)malloc(sizeof(LNode));
    L->next = NULL;
    LNode *s, *r = L;
    scanf("%d", &x);
    while (x != 9999)
    {
        s = (LNode *)malloc(sizeof(LNode));
        s->data = x;
        r->next = s;
        r = s;
        scanf("%d", &x);
    }
    r->next = NULL;
    return L;
}
void printlist(LinkList L)
{
    LNode *t;
    t = L->next;
    while (t != NULL)
    {
        printf("%d", t->data);
        t = t->next;
    }
}
bool reverse(LinkList &L)
{
    if (L == NULL)
        return false;
    LNode *p, *q;
    p = L->next;
    q = p;
    L->next = NULL;
    while (p != NULL)
    {
        q = q->next;
        p->next = L->next;
        L->next = p;
        p=q;
    }
    return true;
}

int main(void)
{
    LNode *L;

    InitList(L);
    printf("shuruzifu:");
    List_TailInsert(L);
    printlist(L);
    printf("First one word is %d\n", L->next->data);
    printf("________\n");
    reverse(L);
    printlist(L);

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
为了封装成 Web 接口,我们可以使用 Flask 框架。首先需要在 Python 中安装 Flask 库。 在 Flask 中,我们需要定义一个路由函数来处理客户端的请求。在本例中,我们可以定义一个名为 `time_series_analysis` 的路由函数,它接受 POST 请求,请求体中包含配件销售数据,返回时间序列分析结果。具体实现如下: ```python from flask import Flask, request, jsonify app = Flask(__name__) @app.route('/time_series_analysis', methods=['POST']) def time_series_analysis(): arr0 = ['2019/1', '2019/2', '2019/3', '2019/4', '2019/5', '2019/6', '2019/7', '2019/8', '2019/9', '2019/10', '2019/11', '2019/12', '2020/1', '2020/2', '2020/3', '2020/4', '2020/5', '2020/6', '2020/7', '2020/8', '2020/9', '2020/10', '2020/11', '2020/12'] date_arr = [] for date_str in arr0: date_obj = datetime.strptime(date_str, '%Y/%m') date_arr.append(date_obj.timestamp()) arr1 = np.array(request.json['data'], dtype=float) data_array = np.vstack((date_arr, arr1)).T.astype(float) df = pd.DataFrame(data_array, columns=['x', 'y']) df = df.dropna() acf, q, p = sm.tsa.acf(df['y'], nlags=20, qstat=True) if (p < 0.05).any(): short_term_dependency = True else: short_term_dependency = False acf, q, p = sm.tsa.acf(df['y'], nlags=20, fft=True, qstat=True) if (p < 0.05).any(): periodicity = True else: periodicity = False adf_result = sm.tsa.stattools.adfuller(df['y']) if adf_result[1] < 0.05: stationary = True else: stationary = False res = sm.tsa.seasonal_decompose(df['y'], model='additive', period=12) if np.isnan(res.seasonal).any(): seasonal_variation = False else: seasonal_variation = True return jsonify({ 'short_term_dependency': short_term_dependency, 'periodicity': periodicity, 'stationary': stationary, 'seasonal_variation': seasonal_variation }) ``` 在定义好路由函数后,我们需要启动 Flask 应用程序。我们可以在 Python 文件中加入以下代码: ```python if __name__ == '__main__': app.run(debug=True) ``` 其中 `debug=True` 参数表示在开发环境下运行应用程序,这样在出现错误时可以输出详细的错误信息。 在启动 Flask 应用程序后,我们可以使用 HTTP 工具(如 Postman)向 `http://localhost:5000/time_series_analysis` 发送 POST 请求,请求体包含配件销售数据。请求体格式如下: ```json { "data": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24] } ``` 其中 `data` 键对应的值是一个包含 24 个数字的数组,表示连续 24 个月的配件销售数据。服务器会对这些数据进行时间序列分析,并返回 JSON 格式的结果: ```json { "periodicity": false, "seasonal_variation": false, "short_term_dependency": true, "stationary": false } ``` 其中 `short_term_dependency` 表示时间序列是否具有短期依赖性,`periodicity` 表示时间序列是否具有周期性,`stationary` 表示时间序列是否是平稳的,`seasonal_variation` 表示时间序列是否存在季节性变化。这些结果可以帮助我们对时间序列进行更深入的分析和决策。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值