Linked List

Passionate Tech Enthusiast | Embracing the Power of DSA, Python Libraries, and Innovative Projects ๐๐ฌ
Welcome to my profile! ๐ As a tech enthusiast, I'm constantly fueled by curiosity and a thirst for knowledge. I thrive on exploring the ever-evolving landscape of new technologies and pushing the boundaries of what's possible.
๐จโ๐ป My Expertise:
๐ก DSA in C++: Currently diving deep into the world of Data Structures and Algorithms in C++. Strengthening my problem-solving skills and optimizing code efficiency are my top priorities.
๐ Python Libraries: I'm well-versed in utilizing various Python libraries like OpenCV, NumPy, and Pandas to develop innovative solutions. Leveraging the power of these libraries, I'm shaping ideas into reality.
๐ฎ Projects: I've had the pleasure of working on exciting projects, including building a Brick Breaker game using Java frameworks, crafting unique Android apps, and even developing a hand recognition model using Python and OpenCV.
๐ My Approach:
I believe in continuous learning and hands-on experience. By embracing real-world challenges and experimenting with cutting-edge technologies, I'm constantly expanding my skill set and nurturing my passion for technology.
๐ Lifelong Learner:
I'm always on the lookout for opportunities to enhance my knowledge and keep up with the rapid pace of the tech industry. Staying updated with the latest trends and breakthroughs enables me to stay ahead of the curve.
๐ค Let's Connect:
I'm eager to connect with fellow tech enthusiasts, industry professionals, and like-minded individuals who share my love for technology. Let's collaborate, exchange ideas, and inspire each other to reach new heights!
โ๏ธ Feel free to reach out to me for exciting discussions, project collaborations, or any tech-related queries. Together, we can create something remarkable and make a positive impact in the world of technology.
#TechEnthusiast #DataStructures #Algorithms #Python #OpenCV #NumPy #Pandas #ProjectDevelopment #LifelongLearner
There are various datatypes in c/c++ and a Linked list is one of them. A linked list is a non-primitive datatype. Just like an array, it can also store homogeneous data in it.
What is the difference between an array and a Linked List?
The main difference between an array and a Linked List is that an array stores the elements in a contagious block of memory while the linked list does not store them in a contagious memory location.
Another difference between them is that the array has a fixed size while the linked list has a dynamic size. In the array, the memory is allocated at compile time while in the linked list the memory is allocated at run time.
Insertion and deletion in the linked list are easy as compared to the array as in the array we need to shift the element.
Types of Linked Lists
The linked list is of three types-:
1.) Singly linked list
2.) Doubly linked list
3.) Circular linked list
4.)Doubly circular linked list
Implementation of linked list
#include <iostream>
using namespace std;
//tie---------------------------------------------------------------->
//creating the node of the linked list
class node{
//defining the data member of this node
//this will containg two things one is
//data and the adress of the next node
public:
int data;
node* next;
//creating the constructor
node(int data){
this->data = data;
//this key word is used as pointer to the
//data in the data memebers
this->next = NULL;
}
//destructor
~node(){
int value = this->data;
while(this->next!=NULL){
this->next = NULL;
delete next;
}
cout<<"delete the node"<<value<<endl;
}
};
//printing the linked list
void print(node* &head){
node *temp = head;
while(temp != NULL){
cout<<temp->data<<" ";
temp = temp->next;
}
cout<<endl;
}
int main(){
node* node1 = new node(10);
node* head = node1;
print(head);
return 0;
}
//take it easy------------------------------------------------------->
A linked list has two fields combined it is known as a node which contains data and a node pointer that points to the next node or in simple words it stores the address of the next node.It also contains a head pointer which points to the first node only.
Insert a node in front of the list
To insert an element in front of the list we can create a function in which we can pass head reference and data to pass as an argument.
//insert at head---->
void insertAtHead(node* &head,int data){
node *temp = new node(data);
temp->next = head;
head = temp;
}
Insert node at any position
To insert a node at any position we need head, position and data to pass as an argument to the function.
In implementing it we need to look for two cases-:
1.)When the position is 1
2.) When the position is anywhere accept 1
//Insert at middle or position--->
void insertAtMiddle(node* &tail,node* &head,int data,int pos){
node *temp = head;
//if position is 1 then
if(pos == 1){
insertAtHead(head,data);
return;
}
int cnt = 1;
while(cnt<pos-1){
temp = temp->next;
cnt++;
}
//if position is last
if(temp->next ==NULL){
insertAtEnd(tail,data);
return;
}
//creatint a new node
node* inMiddle = new node(data);
inMiddle->next = temp->next;
temp->next = inMiddle;
}
So this is it for now Thank you for your time ๐.