[ home / overboard ] [ spam ] [ soy / qa / raid / r ] [ int / pol ] [ a / an / asp / biz / mtv / r9k / tech / v / sude / x ] [ q / news / chive / rules / pass / bans / status ] [ wiki / booru / irc ]

A banner for soyjak.party

/tech/ - Soyence and Technology

Download more RAM for your Mac here
Catalog
Email
Subject
Comment
File
Password (For file deletion.)

File: 1772165695279542.jpg 📥︎ (230.9 KB, 843x1019) ImgOps

 â„–31857[Quote]

modern day coders cant reverse a linked list without ai

 â„–31859[Quote]

I didn't look up the solution but I had to look up what a linked list was because I've never used one. Here is my answer:
Traverse through the whole list following the pointers and and count each jump
malloc the size of the list based on the number of jumps multiplied by the datatype size
traverse backwards and store each element while optionally freeing each old element

 â„–31860[Quote]

>>31859
>I had to look up what a linked list was
bro… we're so cooked.

 â„–31861[Quote]

File: 1776026371015i.mp4 📥︎ (745.7 KB, 496x640) ImgOps

>>31860
They sound retarded and a really good way to fragmentate the shit out of your memory

 â„–31862[Quote]

I'm tired and about to go to sleep, so off the top of my head the solution may not be optimal. My idea is when we're on element n of the list, we keep n-1 and n-2, reverse the link between those, and we still have a link to go forward from n.

 â„–31863[Quote]

>>31861
Why not just start by mallocing an array of some arbitrary size. When you need to append a value, you just append a value at an index and increment the index. When you need to delete a value, you swap it with the value at the index and decrement the index. When the array is full, you malloc another. When its empty you free it.

 â„–31866[Quote]

>>31863
that's similar to how heap works btw

 â„–31901[Quote]

File: ClipboardImage.png 📥︎ (92.45 KB, 825x567) ImgOps

did this in 30m but it may not exaclty be what nophono cares fan about. listtolink transforms a [list] to a linked list. so basically you have these slf node123124324 variables who hang around and they point to another variable etc. then you can reverse it with linktolist. the random shit is to make the node943943 variables. it checks if the variable already exists before creating it, if not tries to make a nu one

 â„–31902[Quote]

>>31901
math major btw so i think you're just fear mongering o algo

 â„–31906[Quote]

File: ClipboardImage.png 📥︎ (121.97 KB, 708x744) ImgOps

>>31901 (me)
>>31902 (also me)
but i mean I still don't really understand the
>usecace
of this at all.

goodered it again award


>import random so it's just like muh pooner humor random potato Xd penguindemonmaster r0fl wew

 â„–31908[Quote]

>>31906
linked lists are useful in the lower languages.

 â„–31911[Quote]

>>31901
the random shit works as a way to prevent overwriting on something. the if a not in nunumber also is important cause if it was already generated but not node'd since the try except would lead to try since node[thing] would already be in nunumber but not as a node already so would lead to the exception

 â„–31912[Quote]

File: IMG_3104.png 📥︎ (812.85 KB, 640x640) ImgOps

Who the fuck cares. When will ever have to do any of this trivial shit? Obsessed trans-arc nigger baby.

 â„–31913[Quote]

>>31908
seems like complicating stuff tbh. why do i need all this anwyay o algo can you show us a concrete usecace?

 â„–31915[Quote]

>>31913
Okay, so if you are writing a program in C, you can only have static sized arrays, i. e. the size of array is constant, so once it's set, it cannot be changed.
In C arrays are just fancy pointers to the consecutive data of the same type. So for example

int arr[] = {0, 78, 10};

creates an array of tree members, indexed from 0 to 2, and stores in memory (in .data segment particularly because it's a global variable)
The size of array can't be changed because it may AND WILL overwrite the variables that come after it.

In memory, this array looks something like this:
| 00 00 00 00 | 00 00 04 0E | 00 00 00 0A |

when you reference array like this
int x = arr[2];
it references data located at address which is stored at array (arr[0]) + sizeof(int) * 2
m'kay?

Now, how do we do dynamic sized arrays in C? Well, linked lists are helpful.
They are implement as structures, a composite data type:

struct LinkedList {
int value;
struct LinkedList *next;

}
This way we can have an array where data is not consecutive but referenced from the previous element, which means we can have as many elements as we want (the pointer of the last element should be NULL btw)

struct LinkedList *ll;

ll->value = 0;

ll->next = (struct LinkedList *)malloc(sizeof(struct LinkedList));
ll->value = 78;

ll->next->next = (struct LinkedList *)malloc(sizeof(struct LinkedList));
ll->value = 10;

ll->next->next->next = NULL;

(this is a plain way to do it, we can create functions which will abstract this code away so we can reference element by index and shi)

But this comes at a cost, because malloc is an expensive memory hogging bitch that will slow your program down by 0.0000000000000000000000001 nanoseconds on modern machines.

 â„–31916[Quote]

>>31915
now to reverse a linked list, we simply add a pointer to a previous element and then simply switch addresses with next pointer

 â„–31917[Quote]

>>31916
at least it works this way in my head

 â„–31947[Quote]

>>31866
I still have yet to autistfag and learn what the stack and heap are geg

 â„–32124[Quote]

File: Oekaki.png 📥︎ (31.59 KB, 480x480) ImgOps

>>31947
let me break it down for you mark



[Return][Catalog][Go to top][Post a Reply]
Delete Post [ ]
[ home / overboard ] [ spam ] [ soy / qa / raid / r ] [ int / pol ] [ a / an / asp / biz / mtv / r9k / tech / v / sude / x ] [ q / news / chive / rules / pass / bans / status ] [ wiki / booru / irc ]