>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?
Jose Jackson
Go read the manga.
Xavier Butler
rape
Zachary Reyes
>whip out dick Reverse this.
Aaron Thomas
Swap every given index with the right, as long as there is a right, for the a length-of-the-list number of times.
Logan Sullivan
>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
Aaron Jackson
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?
Lincoln Ramirez
>but i already got the job why are you making me do this
Brayden Cruz
>it's your job
Jordan Peterson
>"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.
Chase Stewart
>linked list is 7GB in size
good luck with that
Julian Howard
>w-what is linked list?
Connor Perry
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
Isaac Nguyen
(defun foo (a) (let (b c) (while a (setf c (cdr a) (cdr a) b b a a c)) b))
Lincoln Morales
>array
Mason Edwards
Fug, i can't read No idea what a linked list is
Evan Murphy
Sup Forums everyone
Gavin Gutierrez
for (int i : (list.length() /2) - 1) list.swap(i,list.length()-i);
I REALLY need this job
Asher Perez
>list.swap(i,list.length()-i); maybe we can hire you to sweep the floors?
Jose Gutierrez
oh my god
Juan Brown
>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
Jaxon Russell
>interviewer tells you to undress and prepare to have rough sex with her >but you wanted her to be gentle
Grayson Johnson
> 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.
Michael Ortiz
UR FIRED ECKSDEE
Sebastian Thomas
# 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)
Juan Cruz
or l = ['a', 1, 5, 'c', 'efigy', 22, 1, 'zzz', 'robocop'] l.reverse() print(l)
Henry Thomas
>you're fired and have to buy me crepes Why would I work for somebody I'm not employed by? Shit thread.
Nicholas Ross
ITT: nobody knows what the fuck is a linked list.
Ok user, 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.
Leo Lewis
ITT this class Node: def __init__(self, value): self.next = None self.value = 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
Joshua Wood
What is behind the censor bar?
Zachary Bell
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.
Bentley Reed
>reversing linked lists in production code without a library Here's how I know you're not actually programmers.
Hudson Sanders
>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.
Camden Powell
There's a difference between knowing when and how to use something and just wasting time duplicating functionality.
Bentley Davis
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
Dylan Rodriguez
>What do? Hang yourself, stupid animeposter
Christopher Reed
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.
Brayden Howard
>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.
Hunter Gray
>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.
Grayson Peterson
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.
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.
Dylan Ross
You don't have to copy the actual data objects, just the pointers in each node. I guess the overhead is negligible.
Luke Moore
>open new terminal >killall vim
Jack Wood
>inplace
Joseph Reed
Hug the loli
Kevin Baker
Writing production code on a whiteboard would be another clue.
Zachary Barnes
>In place
Jaxon Peterson
Ah wait, the while(b.next) is retarded since it won't do the last item should be a do_while then
Parker Richardson
tsil
Is this good enough? This programming stuff is hard. Also when are we having lunch?
Kayden White
nodes[len-1].child=nodes[0]; nodes[0].child=NULL;
int i; node *first_node = nodes[0];
for(i=1;i
Ryan Hill
>gets asked to reverse a list >rotates the list instead
Blake Evans
shit, sorry
Leo Powell
fuck idk I'm pretty high right now
Parker Ross
>reverse(list) what now, slut?
Jace Cook
holy fucking balls why does evil this great even happen
Ian Bell
>mfw i did an o(n2) solution
Andrew Wood
how do you intend to accomplish your dreams without any money? leeching off the government and/or your parents isn't virtuous either
Zachary Morgan
> i am not here to code for you, butterface
Dylan Stewart
u japanese?
Ryan Garcia
start the cursor at the beginning of the linked list, pop off the back, insert at cursor, advance cursor, repeat
Hudson Barnes
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
Nolan Hernandez
Well, you never said I had to use O(1) extra memory.
I'll make an array of pointers to each of the nodes and use that to repeatedly swap the data fields of each node i with node n - i, where n is the number of nodes.
Isaiah Hughes
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.
Christian Lewis
why is a 3 headed dragon my new boss?
Asher Sullivan
Haven't tested it yet, but I'd be thinking something like this:
>in place I thought this was a functional programming position.
Jacob Rodriguez
ANGEL Club 2017-09 bowalia - "暴淫暴食"
Xavier Carter
You're hired.
Ryder Foster
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.
Anthony Campbell
any run time requirements? else the solution is pretty is easy
Jeremiah Jones
my lil nigga can't be this based
Mason Price
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
Brody Turner
walk = head while (walk != tail) tail->next = walk walk = walk->next whats next