[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
>>51224176 I'm using a TreeMap data structure for
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /g/ - Technology

Thread replies: 12
Thread images: 1
File: file.png (64 KB, 676x684) Image search: [Google]
file.png
64 KB, 676x684
>>51224176

I'm using a TreeMap data structure for the first time, and I'm trying to write a program that finds the most popular/occurring integer entered. I can display the integers entered as keys and the occurrence of each as the values.

I don't know how to translate this information into something where I can state/display which integer, or integers, occurred the most. Can some one explain the logic that goes with this? I can't really think of an algorithm to display the most occurring elements. in the map, or any other data structure for that matter really.
>>
treemap can only sort by key, so it doesn't work. use a hashmap loop through the entries and keep track of the key with the largest value
>>
>>51236413
Shieet. Will try this m8.
>>
>>51236335
>takes integers as input
>specifically state 0 is an acceptable input
>uses 0 as sentinel
Off yourself, retard
>>
>>51237581
Shieeeeeeeeeeeeeet.

I meant to exclude zero. I originally had sentinel as 999, but it was a pain in the ass to type so I changed it to zero, just forgot to change the domain.

In all fairness, its just the loose definition of an integer, and it becomes clear afterwards that 0 isn't acceptable.

I take my shieeet back.
>>
>>51237623
>its just the loose definition of an integer
No, there's a pretty clear definition of what an integer is. Maybe you're thinking about natural numbers.

Why not just use an empty line as a sentinel, so you don't try to redefine well defined words out of ignorance?
>>
>>51237678
0 is easier to just push and go. Its nice yo. And in fairness to me, the definition I put for integers is pretty spot on. So I'll retract the word loose and add the word exactimundo.
>>
>testing your program by manually entering the test data
>>
>>51237888
Its only three integers.
>>
>>51237905
Sure, but how many times have you entered them already?
>>
>>51237941
Twice
>>
>>51237948
the point is that you need to figure out how to create "unit tests" for your program, so that the behavior can be verified automatically

it's unfortunate that they don't really teach software testing in school very often, but it is very valuable.
Thread replies: 12
Thread images: 1

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.