Link List
Link List
Bank :-
10 employees.
Name(String), mobilenumber(Int), address(Staring), family members
Class Employees {
String Name,
Int mobile,
Staring address
}
#include <bits/stdc++.h>
using namespace std;
class employee{
public:
string name;
int mobile;
};
int main() {
employee abc;
abc.name = "Qwer";
cout<<abc.name;
return 0;
}
20 NULL
#include <bits/stdc++.h>
using namespace std;
struct singlyLinkList {
int value;
singlyLinkList* next = NULL;
singlyLinkList(int number){
value = number;
}
};
int main() {
singlyLinkList* head = NULL;
head = new singlyLinkList(20);
singlyLinkList* second = new singlyLinkList(30);
head->next = second;
singlyLinkList* third = new singlyLinkList(50);
second->next = third;
head->next = third;
while(head!=NULL){
cout<<head->value<<" ";
head = head->next;
}
//create anode;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
struct singlyLinkList {
int value;
singlyLinkList* next = NULL;
singlyLinkList(int number){
value = number;
}
};
int main() {
singlyLinkList* head = NULL;
for(int i=0;i<10;i++)
{
head = addNode(i, head);
}
while(head!=NULL){
cout<<head->value<<" ";
head = head->next;
}
//create anode;
return 0;
}
#include <bits/stdc++.h>
using namespace std;
struct singlyLinkList {
int value;
singlyLinkList* next = NULL;
singlyLinkList(int number){
value = number;
}
};
int main() {
singlyLinkList* head = NULL;
for(int i=0;i<10;i++)
{
head = addNode(i, head);
}
// add 10 end of list 0 1 2 3 4 5 6 7 8 9 10
// add 10 at first position 10 0 1 2 3 4 5 6 7 8 9
// add 10 at 4 th position 0 1 2 10 3 4 5 6 7 8 9
//create anode;
return 0;
}
https://www.codechef.com/AUG21/?itm_medium=navmenu&itm_campaign=AUG21
1->2->3->4->5->6
1->3->4->7
1->2->3
1->2->3
(a+b)%mod = (a%mod+b%mod)%mod
Question :- Given a SLL. find the middle node of the link list.
3->6->8->10->12
Answer :- 8
3->6->8->10->12->13
Answer :- 8,10
Question :- Given a SLL. check if the list creates a loop.
Node{
Int value,
Node * next,
Node * another
}
DPP:-
https://leetcode.com/problems/linked-list-cycle/
https://leetcode.com/problems/intersection-of-two-linked-lists/
https://leetcode.com/problems/coin-change/
struct singlyLinkList {
int value;
singlyLinkList* next = NULL;
singlyLinkList* nextOne = NULL;
singlyLinkList(int number){
value = number;
}
};
https://leetcode.com/problems/lru-cache/
https://practice.geeksforgeeks.org/explore/?category%5B%5D=Linked%20List&page=1&
category%5B%5D=Linked%20List
0 to 1
2 to 2
3 to 4
5 to 8
9 to 16
17 to 32
33 to 64
struct DoublyLinkList {
int value;
DoublyLinkList * next = NULL;
DoublyLinkList *pre=NULL;
singlyLinkList(int number){
value = number;
}
};
#include <iostream>
using namespace std;
struct doublylinklist{
int value;
doublylinklist*next=NULL;
doublylinklist*pervious=NULL;
doublylinklist(int number){
value=number;
}
};
int main() {
// your code goes here
doublylinklist* head = NULL;
head = new doublylinklist(5);
doublylinklist* second = new doublylinklist(7);
head->next=second;
doublylinklist* third=new doublylinklist(0);
doublylinklist* four=new doublylinklist(8);
doublylinklist* five=new doublylinklist(6);
second->next=third;
third->next=four;
four->next=five;
// reverse connectiong
five->pervious=four;
four->pervious=third;
third->pervious=second;
second->pervious=head;
doublylinklist* temp = head, *lastNode;
while(temp!=NULL)
{
cout<<temp->value<<" ";
lastNode = temp;
temp=temp->next;
}
cout<<endl;
//rever travel
while(lastNode !=NULL){
cout<<lastNode->value<<" ";
lastNode = lastNode->pervious;
}
return 0;
}
HashMap:-
Map<int, int>