This week's giveaway is in the Testing forum.We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!

# Thomas Nilsen

Greenhorn
since Apr 03, 2015
Cows and Likes
Cows
0
In last 30 days
0
Total given
0
Likes
0
0
Total given
0
Given in last 30 days
0
Scavenger Hunt
Ranch Hand Scavenger Hunt
Greenhorn Scavenger Hunt

## Recent posts by Thomas Nilsen

Tushar Goel wrote:Just wondering the requirement in this case. Inorder generally performed on binary search tree. After performing swap, tree is no more abide the
pre-condition(left child is less than root and right child is greater than the root).

I just did inorder to get a look at the output, to see if my function worked.
7 years ago
I'm trying to write a function that performs a swap on all the children of nodes at a given depth.

Say we have a tree like this:

And an array containing the depth of nodes I want to perform a swap on.

If the array contains 1 then we swap all the childs of nodes at that depth. The tree would then look like this:

My function looks like this:

When I run this method on the example tree, and perform a inorder traversal of the tree, it gives me
7 years ago
I came across an interesting programming challenge, which I'm trying to solve.

In my mind Dijkstras algorithm is the best solution, since what they're essentially asking is to find the shortest path in a un-directed graph.

Here is my solution, but I don't get the correct answer, so I'd like some feedback on my code. Maybe my mistake is obvious.

Any help on the would truly be appreciated!

7 years ago

Tony Docherty wrote:

Do you have any specific date formats in mind?

How about 2 Mar 15 or 1/4/15 or dd-mm-(yy)yy (traditional Danish) or yyyy年m月d日 (Chinese)

Months as actual text which cannot be parsed to ints is a problem...

dd-mm-yyyy will work, but not with dd-mm-yy.

But, when you write year with only yy, how will one know if i mean 2020 or 1920 for example?
7 years ago

Knute Snortum wrote:I don't think it will validate mmddyy with or without separators. This is because the constructor always assumes day, month, year.

Not mmddyy, because I assume year is 4 digits. see my answer above for what date version it accepts right now..
7 years ago

Junilu Lacar wrote:But what happens when someone wants to validate a date that's not formatted in a way that you have defined in one of these enums? Seems like this design violates the Open-Closed Principle

Do you have any specific date formats in mind?

Right now it accepts:
DDMMYYYY
MMDDYYYY
YYYYMMDD

DD.MM.YYYY
MM.DD.YYYY
YYYY.MM.DD

DD-MM-YYYY
MM-DD-YYYY
YYYY-MM-DD

DD/MM/YYYY
MM/DD/YYYY
YYYY/MM/DD

Only thing I can think would be if one would set a 2 digit year (YY)?
7 years ago

Junilu Lacar wrote:Your choice of using an enum for this seems a little strange to me. It doesn't fit my mental model of an enum.

I actually worked "backwards".

I started out by asking myself - How do I want to call the validation method, and set the date format at the same time? Enum seemed like the most logical choice to me.
You could do so much more with enum in java as opposed to other languages.
7 years ago
I'm fairly new to java, and is just building small programs to get the feel for the language. Any tips on how I can improve this code would be greatly appreciated.

7 years ago