Aron Silvester

Ranch Hand
+ Follow
since Sep 23, 2013
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
1
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 Aron Silvester

I found this primMST java class source code online for the prim algorithm. It was accompanied by another class called BinaryMinHeap, which is used in the primMST class. I copied and pasted the primMST code in NetBeans, and it gave me error labels in the text editor for three classes that were used in the primMST class. They are class Edge, Graph, and Vertex.

There was another error for class List, but I fixed that by using the import statement import java.util.*;

Is there an import statement for the class called "Edge", "Graph", and "Vertex"? I've been searching google but I couldn't find anything. Below is the source code for primMST class.

2 years ago
I'm comparing 4 types of sorting algorithms. Bubble sort (pair-wise), selection sort, merge sort, and quick sort. How do I go about finding out what each algorithms memory usage so I can compare them to each other???
4 years ago
It worked. Thank you guys so much!!!
4 years ago

Winston Gutkowski wrote:

Aron Silvester wrote:For my text file I used microsoft word and typed in the strings. I saved it normally. Once saved on my desktop I proceeded to add .txt at the end of the name. Is that how you save the text files for these? Maybe that's causing the problem?


Possibly. A Word file definitely isn't the same as text. Use Notepad, or alternatively download a text editor - there are gazillions out there, including several that "understand" Java code and display in nice colours for you.

Unfortunately, I'm a Linux user now, so I've forgotten all things Microsoft.

Winston



I'm suspecting that the way I created the text file is the one that's cousin the problem.

Okay I've created another file (not using microsoft word). I used my mac's built in text editor. When I ran the program again, now the print statement ("Hello") in the while loop executed 4 times. Before when I used the microsoft file the print statement in the while loop did not execute.

But now there's a bunch of weird words. Here is the output. Still did not print the names in the text file though.

run:
Printing out the length of the file
351
Hello World
Hello World
Hello World
Hello World
{\rtf1\ansi\ansicpg1252\cocoartf1404\cocoasubrtf13 0 {\fonttbl\f0\fswiss\fcharset0 Helvetica;} {\colortbl;\red255\green255\blue255;} \margl1440\margr1440\vieww10800\viewh8400\viewkind 0 BUILD SUCCESSFUL (total time: 0 seconds)
4 years ago

Stevens Miller wrote:Java is pretty good about handling the inconsistent ways that Linux/Unix and Windows handle the "/" and "\" characters, but I wonder if you are having some problem related to that. What operating system are you using? I'm using Windows. Cutting and pasting your posted code, with the only change being from "/Users/regies/NetBeansProjects/Sanchez_Project#2/ListOfNames.txt" to "/Users/smiller/ListOfNames.txt", it runs fine for me.

Use a debugger and step through your code line by line. If the while loop isn't even being entered, it means that the call to inputFile.hasNext() is returning false, which can only mean your Scanner thinks it is looking at an empty File. So, I'm guessing your problem is at Line 22. Use a debugger and let us know what you find there.



Okay I will do that but quick question. For my text file I used microsoft word and typed in the strings. I saved it normally. Once saved on my desktop I proceeded to add .txt at the end of the name. Is that how you save the text files for these? Maybe that's causing the problem?
4 years ago

Stevens Miller wrote:Runs fine for me, Aron. The code you posted should print five lines, one for each name in your file, and a fifth line with all four names on it. What you describe as your output doesn't show the first four lines, which should appear even if the Strings are all null references. Have you posted exactly what your source code is?

By the way, cross-posting the same question to more than one forum is frowned upon. Some people think it is a pretty big deal, while others don't, but it can lead to people spending time and effort in one forum, trying to help you, after people in the other forum have already solved your problem for you. Best practice is to pick one and stick with it for a given question. I'd recommend coderanch.com, but I'm a bit biased about that.



Okay sorry bout that, I'll keep that in mind next time. My while loop is not executing, I put print statement in the loop and it did not print, so therefore it's not entering the while loop, which I don't know why.
4 years ago

Winston Gutkowski wrote:

Aron Silvester wrote:The output when I run this is:
run:
null null null null BUILD SUCCESSFUL (total time: 0 seconds)


That's odd, because even if it's wrong (and nothing leaps out at me) I'd expect it to be
null
null
null
null null null null null BUILD SUCCESSFUL...

Are you sure you're running the exact code you showed us?

Winston




Yes I am running the exact same code.

Actually I put a print statement in the while loop to see if it's executing. The print statement did not execute.

Also, I'm pretty sure that the program has access to my text file, if it didn't it would be giving me a file not found exception. So it's no that.
4 years ago
I'm using java to write this code

I have a text file that has the following strings:
John
chris
Zonado
Buggy

The output when I run this is:
run:
null null null null BUILD SUCCESSFUL (total time: 0 seconds)

What is causing these null outputs? My array has the right amount of size to store the 4 strings.

CROSS POST LINK HERE: Need help reading text from files


4 years ago

Winston Gutkowski wrote:

Aron Silvester wrote:Which type of sorting algorithm do you think is easier to implement? heap, shell, cocktail, bucket, or radix sorts?


My opinion (from easiest): cocktail, radix, bucket, heap, shell.

That's not to say that easiest is smallest though; simply that it's the easiest to understand. And I don't quite know what it gets you.

And (as you've probably gathered) I like heapSort because it involves heaps, which are extremely useful things to know about on their own.

Winston



I forgot to put quick sort. Where in your opinion would quick sort be?
4 years ago
I just realized that we don't do swaps in merge sort, so I guess we only compare.
4 years ago


QUESTION: I found the merge sort algorithm located above online. Since I want to know how many swaps this code will do I'll just put a counter. I created a mergeSortCompareCount which counts the number of compares and another variable mergeSortSwapCount which counts the number of swaps. These variables are bolded so you can spot them easier. I've input them in the code below. Are they in the right place???





4 years ago

Aron Silvester wrote:The code below is for a bubble sort list wise (selection sort). I've gone over it multiple times but I don't know why it doesn't sort the numbers from ascending order. Below is the code and its output. What do you think is causing this? This by the way is from a youtube video.

BUBBLE SORT CODE LIST WISE (SELECTION SORT):


OUTPUT:
run:
Array before sorting:
1 6 5 8 9 4 3 2
*************************************
Array after sorting with bubble sort
1 6 5 8 9 4 3 2







Never mind I figured it out. Thanks.
4 years ago
The code below is for a bubble sort list wise (selection sort). I've gone over it multiple times but I don't know why it doesn't sort the numbers from ascending order. Below is the code and its output. What do you think is causing this? This by the way is from a youtube video.

BUBBLE SORT CODE LIST WISE (SELECTION SORT):


OUTPUT:
run:
Array before sorting:
1 6 5 8 9 4 3 2
*************************************
Array after sorting with bubble sort
1 6 5 8 9 4 3 2




4 years ago
Starting out with JAVA From Control Structures through Objects 5th EDITION.
4 years ago
Which type of sorting algorithm do you think is easier to implement? heap, shell, cocktail, bucket, or radix sorts?
4 years ago