Java #1 - Singly Linked List Tutorial w/ Implementation & Problem Solving - Reversing & Element Find

preview_player
Показать описание
Your contributions made this content possible!

Welcome to the first episode of Java Development! In this particular video, we will be looking at Singly Linked Lists. My goal is not to bore you with theory, but instead walk you through the implementation of the entire thing.

I will follow-up with a few problems most commonly asked when talking about Linked Lists: Reversing the list & finding / removing an element from the list.

Enjoy and stay tuned for more!

Get in touch:

Software:

Relevant Links:

Relevant Search Terms:
EEEnthusiast, Vlad Romanov, Volodymyr Romanov, java linked list, java linked list tutorial, java linked list example, java singly linked list tutorial, java linked list queue, linked list reverse java, linked list reverse traversal, linked list delete node, linked list problems, linked list problems java, linked list questions, linked list interview questions, linked list solutions, linked list implementation in java, linked list data structure, linked list explained, linked list program in java, linked list interview questions and answers
Рекомендации по теме
Комментарии
Автор

Finally, a tutorial that can help university students. All the other ones show you how to implement the correct List class, which you can almost never use to solve the uni problems with data structures.

Cllf
Автор

Simple print method I added:

public void printElements() {
Node<T> selected = head;
int position = 0;
while(selected != null){
System.out.println("Node: '" + selected.element + "' at position " + position + ".");
selected = selected.getNext();
position++;
}
}

Bboyman
Автор

Something I had to clarify for myself:

public void reverseList() {
if (size <= 1) {

} else if (size == 2) {
//At the beginning:
// 'head'
// 'tail'
System.out.println();

// SWAPPING TWO ELEMENTS OF SINGLY LINKED LIST (OF TWO ELEMENTS) WITH EACH OTHER

//Our tail pointing to head: (but it is still 'tail')
tail.setNext(head); // Checking:
System.out.println("tail is " + tail.element); // 'tail is tail'
System.out.println();

//Referencing our tail also as head (now they are referencing the same object("tail"))
head = tail; // Checking:
System.out.println("head is " + head.element); // 'head is tail'
System.out.println("tail is " + tail.element); // 'tail is tail'
System.out.println();

//(the next was the most tough to understand)

// This will swap the nodes. As 'head' now points to (is referencing) 'tail'
// (see above), then (as you see below)
// head.getNext(); gives us 'head'
tail = head.getNext(); // Checking:
//'head'
System.out.println();
// So, now:
System.out.println("tail is " + tail.element); //'tail is head'
System.out.println("head is " + head.element); //'head is tail'
System.out.println();

// Setting tail's next to null
// Checking before:
System.out.println("tail's next is " + tail.next.element); // 'tail's next is 'tail''
tail.setNext(null); // Checking after:
System.out.println("tail's next is " + tail.next); // 'tail's next is null'
// Note: if you put it (above) 'tail.next.element' - you'll get NPE exception!
}
}

PS Подзапутал ты меня немного вот с этим: tail = head.getNext();
Можно было и вот так (легче понимается): tail = tail.getNext();
Спасибо! ;)

pokrova
Автор

Thanks, way more helpful than my professor!

MegaSzymn
Автор

good video. You def need to know some coding to understand this video. it helped me out thanks

fedvgo
Автор

great content, it's helping me alot

benammba
Автор

May I know this is list adt implement in linked list?

johnchong
Автор

did we use the constructor Node(int e, Node n)? cause I don't believe so.. how do we use it?
Say I want to copy a list of integers to this linked list, how do I do that?

yousifsalam
Автор

what does size==0 indicate ? for it to be head=tail, shouldn't the size be 1?

serdashehu
Автор

Mate it doesn't work using your hands to illustrate stuff. We don't know which side is the front and which the back. Whether left hand side denotes the front or back of a list of items is arbitrary, plus you may or may not have transposed for the benefit of the viewer (your left is our right and vice versa).

MrMikomi
Автор

your software on git hub is not present anymore why?

charbelantoinehanna
Автор

It would be better to display some prerequisites before actual coding. I mean you have to have some serious background in terms of programming in order to understand this tutorial...

iKostanCom
Автор

Lol your explanation confused me so much.

CODINC
visit shbcf.ru