Well, I can point you to a good example of dungeon generation: Pixel Dungeon. Here is the code, you want to look at:
*it's in java
Can't recommend anything else, try to search a bit about BSP dungeon generation. That's one of the methods, that I use.