张翔洲 2019-04-07 17:46 采纳率: 0%
浏览 267

求助:如何解决单向链表的删除函数出的问题?

删除函数出问题了……

#include <iostream>
#include <ctime>
#include <cstdlib>
#include <cstdio>
using namespace std;
struct node {
    int data;
    node *next;
};

int initialize(node *head, int datalist[]) {
    static int size = sizeof(datalist);
    static int n = 0;
    if(n>size)
        return 0;
    head->data = datalist[n];
    n++;
    head->next = new node;
    initialize(head->next,datalist);
    return 0;
}

int traversing(node *head) {
    static int size = sizeof(head);
    cout << head->data << ' ';
    size--;
    if(size<=0)
        return 0;
    traversing(head->next);
    return 0;
}

int deletenode(node *head, int data) { 这个函数有问题  
    static int size = sizeof(head);
    static int q = 1;
    if(q == 0)
            return 0;
    size--;
    if(size<=0)
        return 1;
    if(head->data == data)
    {
        head->data = head->next->data;
        node *box = head->next;
        head->next = head->next->next; 
        delete box;
        q = 0;
        return 0; 
    }else
    {
        deletenode(head->next, data);
        if(q == 0)
            return 0;
    }
}

int main() {
    srand(time(0));
    node *head = new node;
    int s[]={1,2,3,4,5,6,7,8};
    initialize(head, s);
    traversing(head);
    cout << "\n";
    deletenode(head,5);
    traversing(head);
    return 0;
}
  • 写回答

1条回答 默认 最新

  • AI创想 2019-04-07 17:50
    关注
    def get_price(skuid):
    url = "https://c0.3.cn/stock?skuId=" 
    r = requests.get(url, verify=False)
    content = r.content.decode('GBK')
    matched = re.search(r'jQuery\d+\((.*)\)', content, re.M)
    if matched:
        data = json.loads(matched.group(1))
        price = float(data["stock"]["jdPrice"]["p"])
        return price
    return 0
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算