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

>you finally land a job offer after 274 consecutive rejection

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 75
Thread images: 7

File: bright eyes fat dragon.jpg (58KB, 960x540px) Image search: [Google]
bright eyes fat dragon.jpg
58KB, 960x540px
>you finally land a job offer after 274 consecutive rejection letters
>OH SHIT
>bright eyes fat dragon is your new boss!
>(in japanese) "Go up to the whiteboard and write a function that reverses a singly linked list in place"
>"you're not allowed to make a 2nd list with the same items pushed in reverse order"
>"you have 10 minutes or else you're fired and you have to buy me crepes"

What do?
>>
>>61942223
Go read the manga.
>>
rape
>>
>whip out dick
Reverse this.
>>
Swap every given index with the right, as long as there is a right, for the a length-of-the-list number of times.
>>
>>61942223
>find length of list
>use this length to perform a bubblesort-like swap pattern
>move 1st element to last place with n "swaps"
>move 2nd element to 2nd last place with n-1 "swaps", etc
>>
>>61942223
Can I just make a flat array of pointers to all of the *next nodes and then swap all the *next nodes in a for loop?
>>
>>61942223
>but i already got the job why are you making me do this
>>
>>61942929
>it's your job
>>
>>61942223
>"you're not allowed to make a 2nd list with the same items pushed in reverse order"
idiotic condition.

find the end_of_original_list
take head of list
insert it after end_of_original_list
and repeat until you reach end_of_original_list (it's already in place).

It's only one list, but you doubled the number of pointer replacements in each step.

>still not allowed
oh well, bye bye job.
>>
>>61943786
>linked list is 7GB in size

good luck with that
>>
>>61942223
>w-what is linked list?
>>
for(int i = 0; i < array.length / 2; i++)
{
var h = array[i];
array[i] = array[array.length-1-i];
array[array.length-1-i] = h;
}

It does an unnecessary switch if you put in odd lenthed arrays, can't be bothered to fix that
>>
(defun foo (a)
(let (b c)
(while a
(setf c (cdr a)
(cdr a) b
b a
a c))
b))
>>
File: 1444801847459.jpg (34KB, 447x353px) Image search: [Google]
1444801847459.jpg
34KB, 447x353px
>>61944456
>array
>>
>>61944639
Fug, i can't read
No idea what a linked list is
>>
>>61944309
>>61944983
/g/ everyone
>>
for (int i : (list.length() /2) - 1)
list.swap(i,list.length()-i);

I REALLY need this job
>>
>>61945155
>list.swap(i,list.length()-i);
maybe we can hire you to sweep the floors?
>>
>>61944983
oh my god
>>
>be interviewing for job
>interviewer rolls away whiteboard
>we won't be needing it this time
>he pulls out this laptop
>opens a terminal
>typed "vim"
>tells me "exit it or no job for you"
REEEEEEEEE I GIVE UP
>>
File: cake muscle.jpg (261KB, 658x945px) Image search: [Google]
cake muscle.jpg
261KB, 658x945px
>interviewer tells you to undress and prepare to have rough sex with her
>but you wanted her to be gentle
>>
>>61942223
> What do?
Impregnate immediately.

Also I don't know why is she asking me programming questions, I'm not one. Maybe they have their interview dates mixed up.
>>
File: 1494912778105.jpg (25KB, 641x530px) Image search: [Google]
1494912778105.jpg
25KB, 641x530px
>>61944983
UR FIRED ECKSDEE
>>
>>61942223
# reverse a list
l = ['a', 1, 5, 'c', 'efigy', 22, 1, 'zzz', 'robocop']

for i in range(int(len(l)/2)):
v = l[i]
l[i] = l[-(i+1)]
l[-(i+1)] = v

print(l)
>>
>>61947021
or
l = ['a', 1, 5, 'c', 'efigy', 22, 1, 'zzz', 'robocop']
l.reverse()
print(l)
>>
>you're fired and have to buy me crepes
Why would I work for somebody I'm not employed by? Shit thread.
>>
ITT: nobody knows what the fuck is a linked list.

Ok Anon, a linked list is a data structure where each node had a "next" and "previous" pointer. Ok, that's a double linked list, but it's the most used type of linked list, specially in code excersices. The most simple way of reversing it is to switch those pointers on each node.
>>
>>61942455
>>61942458
>>61944456
>>61945155
>>61947021
>>61947077
ITT this >>61947143

class Node:
def __init__(self, value):
self.next = None
self.value = value

def append(self, value):
curr = self
while curr.next:
curr = curr.next
curr.next = Node(value)

# make a list
head = Node(0)
for i in range(1, 10):
head.append(i)

# print the list
curr = head
while curr:
print(curr.value)
curr = curr.next

# reverse the list
prev = None
curr = head
next = None
while curr:
next = curr.next
curr.next = prev
prev = curr
curr = next
head = prev

# print the list
print("reversed")
curr = head
while curr:
print(curr.value)
curr = curr.next
>>
>>61945252
What is behind the censor bar?
>>
Normal fags shitting up my board like getting a job is an accomplishment and that you should be proud.

Meanwhile a job is the ultimate cucked. Good luck accomplishing your dreams when you're slaving away 8 hours a day to the man.
>>
>reversing linked lists in production code without a library
Here's how I know you're not actually programmers.
>>
>>61948123
>using an algorithm or a data structure without having at least a basic idea about how it works so you can pick the right tool for the job
Here's how I know you're a ninja rockstar copypaste artisan.
>>
>>61948198
There's a difference between knowing when and how to use something and just wasting time duplicating functionality.
>>
Maybe I don't understand the at question, but can't I just do this?
1. do (pointer of next node = pointer of current node) until pointer of next node is the end
2. make the pointer of th first node the end
>>
>>61942223
>What do?
Hang yourself, stupid animeposter
>>
>>61948241
The context of this thread is an interview question.
If you know what a linked list is but can't write a program to reverse then you're lacking something very fundamental.
>>
>>61948282
>you finally land a job offer after 274 consecutive rejection letters
He's already got the job you fucking idiot. The correct answer is tell her you'll get it done and use a library.

>If you know what a linked list is but can't write a program to reverse then you're lacking something very fundamental.
I never said I couldn't, you fucking idiot.
>>
>>61948305
>you fucking idiot
>you fucking idiot
At least switch it up a bit.

The question exactly describes the data structure and specifies a set of constrains.
The fat loli clearly noticed that you're spending 95% of your time on stackoverflow so she's giving you a chance to redeem yourself by showing that you can actually write an algorithm without looking it up.
>>
>>61947768
The title of the doujin and the author's name. The cunt doesn't want us to know who it is and trying to use saucenao and Google will give 0 results because of it.
>>
>>61942223
reverse' :: [a] -> [a]
reverse' (x:xs) = (reverse' xs) ++ [x]
reverse' [] = []
>>
A = LL
B = A.next
C = B.next
while(B.next){
B.next = A
A = B
B = C
C = B.next
}

Something like this for a singly linked list. Doubly linked would be even easier.
>>
>>61943805
You don't have to copy the actual data objects, just the pointers in each node. I guess the overhead is negligible.
>>
>>61945233
>open new terminal
>killall vim
>>
>>61948683
>inplace
>>
>>61942223
Hug the loli
>>
>>61948123
Writing production code on a whiteboard would be another clue.
>>
>>61948683
>In place
>>
>>61948745
Ah wait, the while(b.next) is retarded since it won't do the last item
should be a do_while then
>>
File: 1500153474054.png (138KB, 538x442px) Image search: [Google]
1500153474054.png
138KB, 538x442px
>>61942223

tsil

Is this good enough? This programming stuff is hard.
Also when are we having lunch?
>>
>>61942223
nodes[len-1].child=nodes[0];
nodes[0].child=NULL;

int i;
node *first_node = nodes[0];

for(i=1;i<len;i++) {
nodes[i-1] = nodes[i];
}

nodes[len-1] = first_node;
>>
>>61948863
>gets asked to reverse a list
>rotates the list instead
>>
>>61948832
>>61948860
shit, sorry
>>
>>61948897
fuck idk I'm pretty high right now
>>
>reverse(list)
what now, slut?
>>
>>61948618
holy fucking balls why does evil this great even happen
>>
>mfw i did an o(n2) solution
>>
>>61947828
how do you intend to accomplish your dreams without any money?
leeching off the government and/or your parents isn't virtuous either
>>
>>61942223
> i am not here to code for you, butterface
>>
u japanese?
>>
start the cursor at the beginning of the linked list, pop off the back, insert at cursor, advance cursor, repeat
>>
>>61945233
esc : q

I have to write shitty scripts in vim all the time.
>open up script, forget to press i before starting to type
>everything fucks up
>esc : q! and reopen file
such is life as pleb
>>
>>61950761

It's called being self sustainable.

Getting a job means you rely on others (your employer) to live. In other words, you're a weak beta who can't provide for himself or your eventual family if you get that far.
>>
>>61942223
why is a 3 headed dragon my new boss?
>>
(node, listhead) = (listhead, null)
while node:
(node.next, listhead, node) = (listhead, node, node.next)

It's not that hard guys.
>>
>>61947143
>double linked list
we'll call you
>>
>>61942223
>leave and look for another job
>>
File: 13814236334.png (11KB, 1600x900px) Image search: [Google]
13814236334.png
11KB, 1600x900px
>>61942223
>in place
I thought this was a functional programming position.
>>
File: firefox_2017-08-17_20-13-35.png (660KB, 682x944px) Image search: [Google]
firefox_2017-08-17_20-13-35.png
660KB, 682x944px
>>61949529
>>61948618
>>61947768
>>61945252
ANGEL Club 2017-09
bowalia - "暴淫暴食"
>>
>>61944983

You're hired.
>>
>>61942223

Are you trying to insinuate that I can't code because I'm a woman? This sexist test is just a bunch of mysogyny and transphobia.
>>
>>61942223
any run time requirements?
else the solution is pretty is easy
>>
>>61951476
my lil nigga can't be this based
>>
>>61942223
Start at first node
Store address
Store pointer to next
Remove pointer to next
Go to next
Replace its pointer by stored address
Repeat from line 2 until no next node
>>
walk = head
while (walk != tail)
tail->next = walk
walk = walk->next

whats next
Thread posts: 75
Thread images: 7


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

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
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.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.