axnjxn's Profile User Rating: -----

Reputation: 14 Tradesman
Group:
Active Members
Active Posts:
144 (0.16 per day)
Joined:
04-February 12
Profile Views:
2,225
Last Active:
User is offline Jul 17 2013 05:43 AM
Currently:
Offline

Previous Fields

Country:
Who Cares
OS Preference:
Windows
Favorite Browser:
FireFox
Favorite Processor:
AMD
Favorite Gaming Platform:
XBox
Your Car:
Who Cares
Dream Kudos:
0
Icon   axnjxn has not set their status

Posts I've Made

  1. In Topic: Eclipse: New Dynamic Web Project Doesn't See Java EE API

    Posted 16 Jul 2013

    Bumped b/c I corrected my post (added code / error list / explanations)
  2. In Topic: Segmentation Fault occurring... sometimes

    Posted 12 Feb 2013

    After running the debugger, I'm getting the following message:

    Quote

    Program received signal SIGSEGV, Segmentation fault.
    0x00401cf6 in findMedian (A=0x46e9948, n=@0x28fed0: 16384000) at problem7.cpp:277
    277 temp[j] = A[i+j];
    (gdb)

    Apparently, the error is happening at the temp[j] = A[i+j] portion of findMedian which is line 17 in the code I posted immediately before this post. I don't think I understand why this would be the location of the SIGSEGV. There is no error on inputs where stat < 8150000. What do you think is causing this?

    EDIT
    It is definitely dependent on the input "stat" (3rd parameter). I ran the program with the smallest input size (1,024,000) and a stat of 1,000,000 and I got the segmentation fault. I tried again with the smallest input size and a stat of 800,000 and got the segmentation fault once again. I had been testing the program with 500,000 so that is working perfectly. I'm at a loss on this one. I'm not very skilled at memory manipulations.
  3. In Topic: Segmentation Fault occurring... sometimes

    Posted 12 Feb 2013

    Blast! I must have forgotten to copy the delete[] portion. I've now altered my code so that the findMedian function looks like this:

    double findMedian(double *A, const int &n){
    	if(n < 2){
    		return A[0];
    	}
    	int remainder = n % 5;
    	int count = 0;
    	if(n / 5 > 0){
    		
    		int size = n / 5;
    		
    		if(remainder != 0) size++;
    		
    		double *medians = new double[size];
    		for(int i = 0; i < (n - remainder); i+=5){
    			double *temp = new double[5];
    			for(int j = 0; j < 5; j++){
    				temp[j] = A[i+j];
    			}
    			insertionSort(temp, 0, 5);
    			medians[count] = temp[2];
    			count++;
    			delete[] temp;
    		}
    		
    		if(remainder != 0){
    			double *temp = new double[remainder];
    			int counter = 0;
    			for(int i = (n - remainder); i < n; i++){
    			
    				temp[counter] = A[i];
    				counter++;
    			}
    			insertionSort(temp, 0, remainder);
    			if(remainder % 2 == 0)
    				medians[count] = temp[remainder/2 - 1];
    			else
    				medians[count] = temp[remainder/2];
    			
    			delete[] temp;
    		}
    		double thisMedian = findMedian(medians, size);
    		delete[] medians;
    		return thisMedian;
    	}else{
    		double *medians = new double[1];
    			
    
    		double *temp = new double[remainder];
    		for(int j = 0; j < remainder; j++){
    			temp[j] = A[j];
    		}
    		insertionSort(temp, 0, remainder);
    			
    		if(remainder % 2 == 0)
    			medians[count] = temp[remainder/2 - 1];
    		else
    			medians[count] = temp[remainder/2];
    		delete[] temp;
    		
    		double thisMedian = medians[0];
    		delete[] medians;
    		return thisMedian;
    	}
    }
    
    

    This eliminates the massive memory leak. However, the segmentation fault is still happening. I will try to debug and see if that helps. Thanks.
  4. In Topic: NOT the same question: Randomized SELECTION not sorting

    Posted 9 Feb 2013

    Yeah. That was my misconception. I realized this after running duplicate arrays through quickselect and then quicksort the duplicate & return the chosen stat. When they were equal after 10 runs of 1 million+ doubles, I realized that quickselect doesn't actually fully sort the array. <Blushing>

    Thanks, Adak.
  5. In Topic: If / else If Statements.

    Posted 9 Feb 2013

    Good call. Integrating that into the code I posted for him.

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Programming Languages:
C++, C, Java, C#

Contact Information

E-mail:
Private

Friends

Comments

axnjxn has no profile comments yet. Why not say hello?