Vincent Jenkins

Greenhorn
+ Follow
since Mar 29, 2015
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
2
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Vincent Jenkins

Carey Brown wrote:Put a print statement before line 19 in qSort().



Did that and it generates about 60 prints before it stops after Run #1
6 years ago

Vincent Jenkins wrote:

Mohamed Sanaulla wrote:I guess its taking time to complete. May be you need to debug to see if its going into the algorithmic implementation. Also Quicksort takes O(n^2) time in its worst case and O(nlogn) in its average case. So you can calculate approximate time taken for the sorting based on input size - n



Is it really just a matter of time? I feel like there's more issues because my CPU usage increases to nearly 100% on run. Unfortunately I have to come up with the counts for each of the types of operations so that I can graph it on a chart for class



Ya... As I let it go nothing else happens. It just stays there forever. If I run it, it will run to like run 5 instantly and just stop. Then the next run it'll get to 7 and hang. Then 4. Then 8. It's just random where it stops. I feel as if there's a case that's forcing it to recurse forever but then that wouldn't make sense because wouldn't the stack overflow? If that's the case how would I see that it's overflowing?
6 years ago

Mohamed Sanaulla wrote:I guess its taking time to complete. May be you need to debug to see if its going into the algorithmic implementation. Also Quicksort takes O(n^2) time in its worst case and O(nlogn) in its average case. So you can calculate approximate time taken for the sorting based on input size - n



Is it really just a matter of time? I feel like there's more issues because my CPU usage increases to nearly 100% on run. Unfortunately I have to come up with the counts for each of the types of operations so that I can graph it on a chart for class
6 years ago
I'm having an issue with quicksort

Here is my main program code



And here is the qsort implementation



Also here is the Car class just for sake of completeness



The implementation will not accept the tests when using input sizes of 100, 200, 300, etc to 1000 but when I change it to 10, 20, 30, to 100 it works just fine. The 100 - 1000 example will only run like 5 runs before it stops, making it to about 500 input size. Is this just a problem with the recursive nature of qsort mixed with a user defined class or is this a problem with my actual code? Would it solve the problem to change it to an array of integers instead?
6 years ago

Knute Snortum wrote:1) Java class names should start with an uppercase letter.

2) There is a lot of code in main(). Generally, main should just launch your program. This is also why all your method have to be static, which is a bad sign.

3) In the method printSec() you have what are called "magic numbers", that is, what's the significance of 7, 2, 8? In general, any number that it not patently obvious should be put into a well-named constant.

Minor: Import for Queue is never used; Lines are too long, try to keep them under 80 characters



So basically I should assign everything to a different class, create an instance of that class object in main and go from there?

Oh ya the code has changed again. My teacher is forcing us to use a queue and so I have a problem now actually. It was working before with the linkedlist but since Queue doesn't have a (get) function because of what it is I'm struggling to figure out how I'm going to implement printQueue now. I've tried poll() since i've read that Java is pass by val but I guess that methods still alter the original object so that doesn't work.
6 years ago
Also here's my total code. Maybe you could throw me some pointers on things I'm doing badly?

6 years ago

Knute Snortum wrote:You probably want:


...which means to start wherever total left off.

Also, you have some bad formatting. It makes it look like the code after:


...isn't under the control of the for loop. From the while loop down should be indented; then you can clearly see you're missing a brace.



Sorry ya. I had that indented when I did it in notepad and only sent part of the code >< I don't like the indenting in this intellij IDE. I think it's terrible how it forces some things for some reason. I might just use notepad++ and compile later. I appreciate the help. I learned something new about the for loop
6 years ago

Campbell Ritchie wrote:Welcome to the Ranch

You mean you want to run a loop, and later start a second loop starting where the first loop left off? Of course you can, but please explain more of what you want because there is probably a better way to do that.



Thanks for the welcome! Basically I'm doing a problem where passengers move from an airport security queue to one of the airport security check gates. The queue starts off with 20 passengers. Here's what I have so far:



Additional information for this problem is that there are 5 security check gates which I will differentiate in my output. Gate 1 can handle 1 person/min, Gate 2 & 3 can handle 2 people/min and Gate 4 & 5 can handle 3 people/min. They always have to go to the next available gate so the security assignment would look like this Gate #1, 2, 3, 4, 5, 4, 5, 2, 3, 4, 5
6 years ago
Is it possible to declare a counter with a value outside of a for loop?

I have a counter that will end prematurely in a while loop during various iterations and I want to pick it back up in a catch all for loop at the end

Let's say I have a while loop

while(something) {
total++
}

then after I have a for loop that I want to start at total but would rather do that then make a new counter variable.

for(total;total < 20;total++)

Is something like this possible or is this a horrible thing to want anyways?
6 years ago