my code does not run for the input 1 and 1000 or any other larger inputs

前端 未结 2 1868
暗喜
暗喜 2021-01-29 14:32

when i am trying to run this code for input 1 and 1000 it shows me segmentation fault .what will be the correction in this code ?

void sorting(int sum[],long int         


        
2条回答
  •  臣服心动
    2021-01-29 15:09

    The segmentation fault is caused by stack overflow. This line:

    int sum[100000]; 
    

    sum uses 400K spaces of stack, which is bigger than the normal size of stack.

    To fix the problem, you can use std::vector to implement sum instead.

提交回复
热议问题