堆栈溢出

问题描述 投票:0回答:0

这是链表将列表转换为整数。 列表到整数转换函数。 对于长度为 31 的情况,它无法正常工作。

`unsigned long long int ListToInt(struct ListNode* list){
    unsigned long long int result=0;
    int length = 0;
    while(list != NULL){
        printf("\nfrk-ListToInt: List: %d", list->val);
        result = result*10 + list->val;
        printf("\nfrk-ListToInt: result: %lld", result);
        length ++;
        list = list->next;
    }
    printf("\nfrank-ListToInt length = %d", length);
    printf("\nfrk-ListToInt: Integer = %lld", result);
    unsigned long long int reverse = 0;

    for (int i=length-1; i>=0; i--){
        reverse += (result%10)*pow(10, i);
        printf("\nfrk-ListToInt: %lld", reverse);
        result /= 10;
    }

    printf("\nfrk-ListToInt: reverse Integer = %lld", reverse);
    return reverse;
}
List to Integer not working properly when length of List is 31.
[1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1]`

如何解决这些问题?

c linked-list overflow biginteger integer-overflow
© www.soinside.com 2019 - 2024. All rights reserved.