Jump to content
  • Advertisement

ZivBenShitrit

Member
  • Content Count

    7
  • Joined

  • Last visited

Community Reputation

100 Neutral

About ZivBenShitrit

  • Rank
    Newbie
  1. ZivBenShitrit

    C# - Merging two sorted arrays - merge sort

    Thank you, a_loho - it worked! Thanks everyone who helped. I have a question - is there a way to implement merge sort without using the extra memory?
  2. ZivBenShitrit

    C# - Merging two sorted arrays - merge sort

    Anyone...?
  3. ZivBenShitrit

    C# - Merging two sorted arrays - merge sort

    Yeah, I'm pretty sure 'right' is inside the array. This is the recursive call function: static void MergeSort(int[] Arr, int left, int right) { if (left == right) return; MergeSort(Arr, left, left + (right - left) / 2); MergeSort(Arr, left + (right - left) / 2 + 1, right); Merge(Arr, left, (right - left) / 2, right); } And this is how I call the function from main: MergeSort(Arr, 0, Arr.Length - 1);
  4. ZivBenShitrit

    C# - Merging two sorted arrays - merge sort

    But I'm increasing RightPtr (Arr[RightPtr++]). Why would it not stop?
  5. Hey, I'm trying to implement a merge sort in C#. I'm having troubles writing the merging function. There's an error and I can't tell why it happens. Here's the code: (the algorithm is the usual one - comparing the first two elements in the arrays each time) static void Merge(int[] Arr, int left, int mid, int right) { int[] TempArr = new int[right - left + 1]; int LeftPtr = left, LeftEnd = mid, RightPtr = mid + 1, RightEnd = right; int Index = 0; while (LeftPtr <= LeftEnd && RightPtr <= RightEnd) { if (Arr[LeftPtr] <= Arr[RightPtr]) TempArr[Index++] = Arr[LeftPtr++]; else TempArr[Index++] = Arr[RightPtr++]; } if (RightPtr > RightEnd) { while (LeftPtr <= LeftEnd) TempArr[Index++] = Arr[LeftPtr++]; } if (LeftPtr > LeftEnd) { while (RightPtr <= RightEnd) { TempArr[Index++] = Arr[RightPtr++]; // This is the error line. It says index was out of range. } } for (int i = 0; i < TempArr.Length; ++i) { Arr[left++] = TempArr; } } Anyone has an idea where could my problem be? Thanks for any help.
  6. ZivBenShitrit

    Projects For Beginners To Do

    +1 on the sorting algorithm task. General Programming: Implementing Prime Sieve algorithm, solving quadric equation / a system of two equations and two variables, solving a simple math term (simple ones with +, -, *, / operators only). Game Programming: Making a simple block breaker game. It was the first game I made.
  7. ZivBenShitrit

    Convex Hull Problems

    Edit: Wow. I feel like an idiot. Instead of decreasing i by one, i should have decreased it by 2. >_< Thanks anyways...
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!