You finally land a job offer after 274 consecutive rejection letters

>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?

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.

>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

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?

>but i already got the job why are you making me do this

>it's your job

>"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.

>linked list is 7GB in size

good luck with that

>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))

>array

Fug, i can't read
No idea what a linked list is

Sup Forums everyone

for (int i : (list.length() /2) - 1)
list.swap(i,list.length()-i);

I REALLY need this job

>list.swap(i,list.length()-i);
maybe we can hire you to sweep the floors?

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

>interviewer tells you to undress and prepare to have rough sex with her
>but you wanted her to be gentle

> 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.

UR FIRED ECKSDEE

# 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)

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 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.

ITT this 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

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.

>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.

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

>What do?
Hang yourself, stupid animeposter

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.

>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.

>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.

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.

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.

You don't have to copy the actual data objects, just the pointers in each node. I guess the overhead is negligible.

>open new terminal
>killall vim

>inplace

Hug the loli

Writing production code on a whiteboard would be another clue.

>In place

Ah wait, the while(b.next) is retarded since it won't do the last item
should be a do_while then

tsil

Is this good enough? This programming stuff is hard.
Also when are we having lunch?

nodes[len-1].child=nodes[0];
nodes[0].child=NULL;

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

for(i=1;i

>gets asked to reverse a list
>rotates the list instead

shit, sorry

fuck idk I'm pretty high right now

>reverse(list)
what now, slut?

holy fucking balls why does evil this great even happen

>mfw i did an o(n2) solution

how do you intend to accomplish your dreams without any money?
leeching off the government and/or your parents isn't virtuous either

> 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

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

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.

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.

why is a 3 headed dragon my new boss?

Haven't tested it yet, but I'd be thinking something like this:

struct node;
struct node {
int data;
struct node *next;
};

void reverse_list(struct node *list)
{
size_t len = 0;
size_t cap = 10;

struct node **buf = malloc(sizeof(struct node*) * cap);
struct node *ptr = list;

/* Make a vector of pointers to all list nodes */
while (ptr != NULL) {
buf[len++] = ptr;
if (len >= cap) {
cap *= 2;
struct node **tmp = realloc(buf, cap);
if (tmp == NULL) { exit(EXIT_FAILURE); }
else { buf = tmp; }
}
ptr = ptr->next;
}

/* Swap elements */
for (size_t i = 0; i < len / 2; i++) {
int tmp = buf[i]->data;
buf[i]->data = buf[len - i]->data;
buf[len - i]-> data = tmp;
}

free(buf);
}

Uses O(n) extra memory temporarily, but no new linked lists are created.

(node, listhead) = (listhead, null)
while node:
(node.next, listhead, node) = (listhead, node, node.next)

It's not that hard guys.

>double linked list
we'll call you

>leave and look for another job

>in place
I thought this was a functional programming position.

ANGEL Club 2017-09
bowalia - "暴淫暴食"

You're hired.

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.

any run time requirements?
else the solution is pretty is easy

my lil nigga can't be this based

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