[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]

Good links to learn linked list completely from scratch

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: 5
Thread images: 1

Please provide me a link to learn link list completely , thank you . If this is not the right board then mention which is a good thread to ask programming related queries .
>>
go ask /g/, raj.
>>
>>18631223
It's not hard mate, if you can't find this out on your own you don't stand a chance of becoming a good programmer.
>>
>>18631223
http://www.geeksforgeeks.org/linked-list-set-1-introduction/
>>
Linked lists are dynamically sized data structures that hold an arbitrary number of entries, and can grow and shrink when items are added or removed.

There are other ways to implement it but the easiest is to create two classes: List and Node. The list holds a reference to the first Node, and each Node has two fields: data and next. As the names imply, data is the data the node holds, and next is a reference to the next Node. e.g.

class List { Node* first; }
class Node[T] { T data; Node* next; }

To get the n-th item of a list you start from the beginning and iterate over the "next" references n times. If at any point the next is a null reference, you exit early and return null.

To count the items you iterate from the beginning to the end and return the number of iterations.

To add prepend an item to the list you create a new Node with its "next" pointing to the first element of the list, and update the List's "first" field to point to that new Node.

To add append an item, you iterate to the last Node and point its "next" to a newly-created Node.

To add an item at the n-th index, you create a new Node with its "next" pointing to the n-th item, and update the n-1'th item's "next" field to point to the newly-created item.

To remove an item, you do these in reverse.

All this is for singly-linked lists since each node has only one link. There's also double linked lists where each node also contains a reference to the previous node which you need to update when adding and removing stuff.
Thread posts: 5
Thread images: 1


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