[Solved] c++ merge sort trouble [closed]

So one small mistake that you don’t take into account is that, you are passing pointer array ini but inside the method you still use the method initial and one more thing is, you should take in a temp array that would assign the sorted values to your ini array. So your code should look … Read more

[Solved] I am getting segmentation fault for merge sort [closed]

That would be a way to go on Linux: Compile your program with debug info (g++ -g merger_sort.cpp -o merger_sort) Load it in debuger: >>> gdb merge_sort Run it: (gdb) run. You will see: Program received signal SIGSEGV, Segmentation fault. 0x0000000000400b1e in merge_sort (A=0x7ffffffddda0, p=0, r=1) look at the position in the code: (gdb) layout … Read more

[Solved] where is the pthread segfault happening?

You use of strtok() is wrong: line = strtok(buffer, NULL); should be line = strtok(NULL, delim); Another mistakes should be fixed similarly. The elements of text_lines are uninitialized: text_lines = malloc(6000 * sizeof(char*)); this allocated 6000 pointers to char, but none of these pointers are initialized. 0 solved where is the pthread segfault happening?

[Solved] Mergesort Python implementation

The mergesort function you call doesn’t modify its argument. Rather, it returns a new sorted list. A simple fix would be: def mergesort(data): if len(data) < 2: return data # Fix1 left = data[:len(data)//2] print(left) right = data[len(data)//2:] print(right) print(“left only now”) left = mergesort(left) # Fix2 print(“right now”) right = mergesort(right) # Fix3 return … Read more

[Solved] How to make a Worst case in mergesort in c? [closed]

The way mergesort works is dividing the array in two arrays, recursively (logn times), untill being able to compare pairs of elements. Then it merges the recursively created arrays also sorting them at the same time. For some sorting algorithms (e.g. quicksort), the initial order of the elements can affect the number of operations to … Read more

[Solved] Merge Sort Python 2.7x

The issue is that with the line arr = ls + rs You are no longer calling merge on the list passed to merge_sort, but rather calling it on a copy. So the original list isn’t being modified. To correct this issue you can have the merge_sort function return arr at the end, then assign … Read more

[Solved] C++ : Unable to read from large txt file [closed]

Your problem is in the merge function: you exceed the local variable c. long c[30]; maybe there are more problems, that is the first I notice. EDIT Try this: find the differences… #include <map> #include <vector> #include <fstream> #include <iostream> #include <time.h> using namespace std; void merge(vector<long> &,long ,long , long ); void divide(vector<long> &arr,long … Read more