• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help removing duplicates from array  RSS feed

Don Havan
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone. I've been a frequent lurker of this site for a while. Nice to finally be able to say hello, and to also say thank you to everyone who regularly helps those of us in need .

After spending some time on paper, I just typed the program and planned on asking for help as to why it doesn't work, but to my surprise, it seems to. This is my first course in Java, so I'm far from experienced, and I wanted to ask if this is the most efficient way of handling what I'm trying to accomplish. In addition to opinions on what I have already written, I was wondering if any more is needed in order for the instructor to deem this A+ work, with regards to whether or not I should take additional measures in dealing with the remaining values. Here's the question: "Write a method called noDups() that removes duplicates from the previously sorted array without disrupting the order, and in O(N) time."

Here's the ArrayIns class of the array and methods (along with my noDups() method), and the InsertSortApp class:

And here's the main method and then the reults:

Which prints the following:

7 2 4 2 2 8 1 6 6 3

1 2 2 2 3 4 6 6 7 8

1 2 3 4 6 7 8

It seems to work. Results of the run were as expected. Is this what is wanted? I mean...is it common-practice to move the remaining values to a new array of the new length? I obviously want to learn the code, but I want to learn popular practices as well. Any feedback would be appreciated.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!