• Login
  • Register
  • Dolphin Forums
  • Home
  • FAQ
  • Download
  • Wiki
  • Code


Dolphin, the GameCube and Wii emulator - Forums › Offtopic › Delfino Plaza v
« Previous 1 ... 14 15 16 17 18 ... 64 Next »

My Regrets - Part {1, 2, 3}/3
View New Posts | View Today's Posts

Pages (3): « Previous 1 2 3 Next »
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Thread Modes
My Regrets - Part {1, 2, 3}/3
10-27-2014, 05:01 AM
#11
rlaugh0095 Offline
God of Conquest
****
Posts: 519
Threads: 28
Joined: Oct 2013
Sorry you didn't get the job. Better luck next time though.

Anyway, was it sega of america by any chance? I googled popular tech companies out there and thats the only one I saw that made sense. o.o
Find
Reply
10-27-2014, 03:57 PM
#12
garrlker Offline
That one guy
***
Posts: 183
Threads: 7
Joined: Feb 2012
(10-27-2014, 05:01 AM)rlaugh0095 Wrote: Sorry you didn't get the job. Better luck next time though.

Anyway, was it sega of america by any chance? I googled popular tech companies out there and thats the only one I saw that made sense. o.o

Whaaaat!? There are so many *more* though.
Gaming Rig
Spoiler: (Show Spoiler)
I5-3570k@4.1Ghz
Gtx 660 TI 3GB Superclocked Edition
20Gb G.Skill DDr3 Ram
1.8 TBs of Storage
Windows 7 64bit
Find
Reply
10-28-2014, 01:15 AM
#13
rlaugh0095 Offline
God of Conquest
****
Posts: 519
Threads: 28
Joined: Oct 2013
(10-27-2014, 03:57 PM)garrlker Wrote:
(10-27-2014, 05:01 AM)rlaugh0095 Wrote: Sorry you didn't get the job. Better luck next time though.

Anyway, was it sega of america by any chance? I googled popular tech companies out there and thats the only one I saw that made sense. o.o

Whaaaat!? There are so many *more* though.

Oh, I didn't see any of those. o.o
Find
Reply
10-28-2014, 05:43 AM
#14
Sonicadvance1 Offline
Professional Hand Holder
**********
Developers (Some Administrators and Super Moderators)
Posts: 716
Threads: 15
Joined: Jan 2013
I actually misremembered in my first post about this being three questions long. It was actually four, but the two in this were fairly similar which is why I misremembered.
In any case, from the first question it was easy to determine that I was going to go in to a downward spiral from there. From this point on we are dealing with a basic binary tree. This is laid out in a very simple way with each node has two children and a string inside of it.
Code:
struct node
{
      char* name;
      node* child_left;
      node* child_right;
};

So the layout is really simple, basically the easiest binary tree representation one can make. So the first simple exercise to do this time around is to output the tree using regular C++ methods. The way the output is wanted is to first output the left child, then the current node, then the right child. So all we get is a function that gets a root node and spams all the output to cout. Here's what the function definition looks like.
Code:
// Example structure:
//        -"bar"-
//       /       \
//    -"foo"-   nullptr
//   /       \
// "baz"    nullptr
// prints string: "bazfoobar"
void print_string(node* root)
{    
}

Fairly simple right? Now there are a couple ways to go about this. We'll just show the one that I managed to generate in my stress filled hour of time.
Code:
if (!root)
      return;

print_string(root->child_left);

std::cout << root->name;

print_string(root->child_right);

Alright, top notch we did it. The code is simple and clean due to the recursion of calling itself. This is about what I got after a bit of fussing around. The only real issue with this code is the fact that we are using recursion. While it makes everything look nice, there is overhead in doing so due to having to build and destroy the callstack throughout each of the calls. Which if you're printing the binary tree you don't really care about speed anyway, so who cares. It may be something to worry about later though. If someone wants to whip up a way to do it without recursion for fun then have at it.

The next exercise is similar to the previous one, this time around we are prepending a string to the binary tree. So basically walk down the entire left side of the tree and stick it on to the very left. The function definition is as follows.
Code:
void prepend_string(node* root, char* name)
{    
}

Alright, so you get a root node and a character pointer. Some additional details are that the new node is generated using regular c++ new routines, and I wasn't told if we are required to generate new address space for the new name string. For the exercise I assume you didn't, this may have been a mistake but really it's a minor implementation details.
Code:
node* current_node = root;

for(; current_node->child_left; current_node = current_node->child_left) {}

current_node->child_left = new node;
current_node->child_left->name = name;

This is roughly the code I generated at the time. Albeit it was probably a fair bit dirtier at the time of writing during the phone conversation. During this point of the interview I was getting exceedingly frazzled and my mind was dying on me from nervousness. Again, I wasn't told if I needed to allocate memory for the new name so I just did an assignment. Which if anything it would be just a simple allocate and string copy.

So these two were fairly easy to do once again, I spent far too long implementing these due to being overly nervous. Probably didn't help that during this time a large amount of vehicles were driving by due to school being let out, and I had decided to do this interview outside a coffee shop. So the next post will be the final question that I completely balls up and wasn't even able to complete even though it was another easy exercise.
Find
Reply
10-28-2014, 09:10 AM
#15
AnyOldName3 Offline
First Random post over 9000
*******
Posts: 3,533
Threads: 1
Joined: Feb 2012
Is it bad that I've been taught so much functional programming, as opposed to regular programming, that I'm converting your code to ML in my head? It's giving me an aversion to reassigning variables, and iteration, and fixed datatypes (as opposed to polymorphic, not dynamic), and basically every other tool that makes making a computer do what you want really easy.
OS: Windows 10 64 bit Professional
CPU: AMD Ryzen 5900X
RAM: 16GB
GPU: Radeon Vega 56
Find
Reply
10-28-2014, 09:56 AM (This post was last modified: 10-28-2014, 09:56 AM by tueidj.)
#16
tueidj Offline
Senior Member
****
Posts: 552
Threads: 0
Joined: Apr 2013
Should have initialized the child pointers in that new node.
Find
Reply
10-28-2014, 10:10 AM
#17
Sonicadvance1 Offline
Professional Hand Holder
**********
Developers (Some Administrators and Super Moderators)
Posts: 716
Threads: 15
Joined: Jan 2013
current_node->child_left = new node();

Fix all the things Tongue
Find
Reply
10-28-2014, 01:03 PM (This post was last modified: 10-28-2014, 01:03 PM by tueidj.)
#18
tueidj Offline
Senior Member
****
Posts: 552
Threads: 0
Joined: Apr 2013
According to the given definition node is a struct (without a constructor), not a class.
Find
Reply
10-28-2014, 01:56 PM (This post was last modified: 10-28-2014, 01:57 PM by shuffle2.)
#19
shuffle2 Offline
godisgovernment
*
Project Owner  Developers (Administrators)
Posts: 698
Threads: 17
Joined: Mar 2009
nope, c++ magic: http://ideone.com/SgKiWt
edit:
also, since c++11: http://ideone.com/JkIyuW (although, it's cheating)
Find
Reply
10-28-2014, 02:36 PM
#20
tueidj Offline
Senior Member
****
Posts: 552
Threads: 0
Joined: Apr 2013
You don't want to make assumptions about the compiler in an interview. It wasn't established that this was C++ instead of C (I intentionally overlooked "node" being undeclared due to lack of a typedef) - use of char* rather than string and non-member functions smells like C...
Find
Reply
« Next Oldest | Next Newest »
Pages (3): « Previous 1 2 3 Next »


  • View a Printable Version
  • Subscribe to this thread
Forum Jump:


Users browsing this thread: 2 Guest(s)



Powered By MyBB | Theme by Fragma

Linear Mode
Threaded Mode