For removing duplicate elements from a linked list. You don't need to iterate over 2 loops: public void deleteDuplicate() { Node current = head; Node next = head.next; while (next != null) { if (current.data == next.data) current.next = next.next; else current = next; next = next.next; } } This also works.
@favazabdulrasheed583 жыл бұрын
Super bro Simple and powerful
@jelanmathewjames25792 жыл бұрын
i Think code need to check whether next is tail or not otherwise tail will lost the connection and new linkedlist will be created with not head
@ashmil83033 жыл бұрын
Reverse single linked list public void reverse() { Node pre = null; Node curr = head; while (curr != null) { Node cnex = curr.next; curr.next = pre; pre = curr; curr = cnex; } head = pre; }
@muhammedrinshid80472 жыл бұрын
this also works public void deleteDuplicate(){ Node temp=head; while(temp.next!=null){ if(temp.data==temp.next.data){ temp.next=temp.next.next; }else{ temp=temp.next; } } }
@mohammedmishal31232 жыл бұрын
ellavarum nalla effort ittu nalla knowledgable contents tharunnu thanks to Nikhil sir and ur wonderful team doubt: the above can only delete the duplicates of same and consecutive data? when I entered 20 10 20 20 output: 20 10 20
@venti6100 Жыл бұрын
sorted list ill mathre eth cheyan pattu
@abhiram8035 Жыл бұрын
In this program the if condition for tail==next doesnt work because the while loop before will make the next null if this scenario arises and this condition will never happen. The program works without it as we dont need to change the tail. it can be written like this. public void removeduplicate() { Node current = head; while(current != null) { Node next=current.next; while(next!= null&& next.data == current.data) { next = next.next; } current.next = next; current = next; } } by brototype student
@minhajmin29514 ай бұрын
bro,1 2 3 3 3 anel,tail maintain cheyyunnudel, tail nte value pinne 2 avunillallo e code l ?,sorry if i wrong
@richard_shaju Жыл бұрын
Selection Sort in linkedList public void sort() { Node temp = head; while (temp != null) { Node small = temp; Node x = temp.next; while (x != null) { if (x.data < small.data) { small = x; } x = x.next; } int t = small.data; small.data = temp.data; temp.data = t; temp = temp.next; } }
@JobinSelvanose3 жыл бұрын
advance congratulations for reaching 100k subscribers.
@arshalabbas3 жыл бұрын
Nikhil Sir: next next next next next Le njan: 🤯🤯🤯 😂😂😂
@redstoneninja33753 жыл бұрын
hi da
@ramsankar43192 жыл бұрын
removing duplicates using a single while loop: public void removeDuplicates(){ Node temp = head; if(temp == null){ System.out.println("empty list"); return; } while(temp.next != null){ if(temp.next.data != temp.data){ temp = temp.next; continue; } temp.next = temp.next.next; } }
@harisankar79582 жыл бұрын
It is very easy to understand the concepts but it is light difficult to implement it in code 🥺😔
@thomastsojan43673 жыл бұрын
public class SinglyLinkedList { static class Node{ int data; Node next; } Node head,tail; int length = 0; // INSERT NODE AT START POSITION void insertStart(int value){ Node node = new Node(); node.data = value; node.next = null; if (head == null){ head = node; tail = node; } else{ node.next = head; head = node; } length++; } // INSERT NODE AT END POSITION void insertEnd(int value){ Node node = new Node(); node.data = value; node.next = null; if(head == null) { head = node; tail = node; } else{ tail.next = node; tail = node; } length++; } // INSERT NODE AT SPECIFIC POSITION void insertPosition(int index,int value){ Node node = new Node(); node.data = value; node.next = null; if(index ==0){ insertStart(value); } else if(index == length){ insertEnd(value); } else { int indexCounter = 0; Node current = head; while (indexCounter < index - 1) { current = current.next; indexCounter++; } node.next = current.next; current.next = node; length++; } } // DELETE NODE AT START POSITION void deleteStart(){ if(head == null){ System.out.println("Linked List Empty"); } else{ head = head.next; length--; } } // DELETE NODE AT END POSITION void deleteEnd(){ if(head == null){ System.out.println("Linked List Empty"); } else{ if(head != tail){ Node current = head; while(current.next != tail){ current = current.next; } tail = current; tail.next = null; length--; } else{ head = tail =null; } } } // DELETE NODE AT SPECIFIC POSITION void deletePos(int index){ if(index == 0) deleteStart(); else if(index == length-1) deleteEnd(); else{ Node current = head; for(int i = 0;i
@shahinshahchelothil3 жыл бұрын
27:25 Exactly My Reaction 😂
@GOODIESS3 жыл бұрын
Head and tail vere oru variable vech exchange cheyth athh reverse aavum
@Ksk93602 жыл бұрын
Aaro paranj manushyanmar swarthigal enn. Njan adine vishwasich. But brototype kanden shesham manaslayi Adhyam njan vishwasichad kallamaanen. (Chumma oru कविता) Oru prathifalam apekshikaadhe ningal cheyunna ee karyamundallo great. Vidya daana shreshtra daana ✌. Brototype channel fan from karnataka ( njan oru videoyil thangal malayaleesn vendi idokke cheyunathenn ket. But non malayaleesum idine kelkunund and practice cheyd Knowledge gain cheyunind). Njanoru nalla devoloper aayen shesham futurl Ee chanelnde perl kannada version videos cheyum❤ .
package sample; public class ReverseList { class Node{ int data; Node next; Node(int data) { this.data = data; } } public Node head = null; public Node tail = null; public void addNode(int data) { Node newNode = new Node(data); if(head == null) { head = newNode; tail = newNode; }else{ tail.next = newNode; tail = newNode; } } public void reverse(Node current) { if(head == null) { System.out.println("empty"); return; } else { if(current.next == null) { System.out.print(current.data + " "); return; } reverse(current.next); System.out.print(current.data + " "); } } public void display() { Node current = head; if(head == null) { System.out.println("empty"); return; } while(current != null) { System.out.print(current.data + " "); current = current.next; } System.out.println(); } public static void main(String[] args) { ReverseList List = new ReverseList(); List.addNode(1); List.addNode(2); List.addNode(3); List.addNode(4); List.display(); List.reverse(List.head); } } O(n)T O(1)S
@orion96863 жыл бұрын
🔥🔥
@yazinsha23703 жыл бұрын
ennikk oru project unnd arengilum ennne help cheyyyuo (tech ayittt)
@DLUXMNI3 жыл бұрын
njan oru freelancer anu so ennne kondu cheyyyan pattunnath njan cheyyydhu thraaam
@yazinsha23703 жыл бұрын
@@DLUXMNI thank you sir
@yazinsha23703 жыл бұрын
@@DLUXMNI egane contact cheyyum
@JobinSelvanose3 жыл бұрын
@@yazinsha2370 i can also help you for sharing more details share you contact details at jobins9633@gmail dotcom
@JobinSelvanose3 жыл бұрын
@@DLUXMNI great
@ajnashibnumer85863 жыл бұрын
♥️♥️
@uv19063 жыл бұрын
❤❤❤❤❤
@nandhu20303 жыл бұрын
First view🥰🥰🥰
@akshaypkk3 жыл бұрын
sonu fan❤❤
@redstoneninja33753 жыл бұрын
100th like :D
@GOODIESS3 жыл бұрын
Enthenkilum comedy parayin changhayimare
@shukoorraother.40223 жыл бұрын
സർ Software engineering ഇൽ programming മാത്രമേ ഉള്ളോ കാരണം എന്നിക്ക് software engineering ഇഷ്ട്ടമാണ് പക്ഷെ programming ഇഷ്ട്ടമല്ല...... please reply...... please
@GAMEOLOGIST3 жыл бұрын
@Joseph George 😂
@jelanmathewjames25792 жыл бұрын
# Class for Linked List O(n)TS All code with reversing a Linkedlist class LinkedList(): # Creating head and tail variable head = None tail = None # Class Node, creating data and next variable on calling this class class Node(): def __init__(self,data): self.data = data self.next = None # Function to add node def addnode(self,data): #creating object node node = self.Node(data) #Checking head is None (head never changes) if self.head == None: #if none placing node object to head self.head = node #if head not none then placing node object to next varible #that points next node next variable contain address of next node #(tail changes) else: self.tail.next = node #placing node object to tail self.tail = node #To display Linked List def display(self): if(self.head == None): print("No Value") return temp = self.head while temp != None: print(temp.data) temp = temp.next #To delete a node def delete(self,data): temp = self.head if temp != None and temp.data == data: self.head = temp.next temp.next = None return while(temp!=None and temp.data != data): previous = temp temp = temp.next if temp == None: return if temp == self.tail: self.tail = previous self.tail.next = None return previous.next = temp.next temp.next = None #To insert node def insertafter(self,addafter,data): newnode = self.Node(data) temp = self.head if(temp != None and temp.data == addafter): newnode.next = temp.next temp.next = newnode return while(temp != None and temp.data != addafter): temp = temp.next if temp == None: return if temp == self.tail: self.tail.next = newnode self.tail = newnode return newnode.next = temp.next temp.next = newnode def deleterepetitiondata(self): current = self.head while current != None: if current.next != None: if current.next != self.tail: if current.data == current.next.data: current.next = current.next.next else: current = current.next else: if current.data == current.next.data: current.next = None self.tail = current break else: break else: break def reverselinkedlist(self): current = self.head next = current.next if next == None: return next_to = next.next if current != None and current == self.head: current.next = None next.next = current if next == self.tail: self.tail, self.head = self.head, self.tail return current = next next = next_to while next != self.tail: next_to = next.next next.next = current current = next next = next_to if next == self.tail: next.next = current self.tail, self.head = self.head, self.tail return
@muhaimenkm13 жыл бұрын
Implemented whole program. You can refer reverse() method for reversing the linkedlist. /** * @author Muhaimen */ public class ReverseLinkedList { Node head = null; Node tail = null; public static void main(String[] args) { ReverseLinkedList list = new ReverseLinkedList(); list.add(10); list.add(20); list.add(30); System.out.println("###DISPLAY BEFORE REVERSING###"); list.display(); System.out.println("###DISPLAY AFTER REVERSING###"); list.reverse(); list.display(); } public void add(int data) { Node newNode = new Node(data); if (head == null) head = newNode; else tail.next = newNode; tail = newNode; } public void reverse() { Node current = head; Node next = null, prev = null; while (current != null) { next = current.next; current.next = prev; prev = current; current = next; } head = prev; } public void display() { Node temp = head; if (temp == null) System.out.println("List is Empty"); while (temp != null) { System.out.println(temp.data); temp = temp.next; } } class Node { int data; Node next; public Node(int data) { this.data = data; } } }