Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions Deletion from a Circular Linked List..cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
#include<iostream>
using namespace std;

class Node{
public:
int data;
Node* next;

};

void push(Node** head, int val)

{
Node* new_node = new Node();
new_node->data = val;

new_node->next = *head;
*head = new_node;
}


void circular(Node* head)
{
Node* temp = head;

while(temp->next!=NULL)
{
temp = temp->next;
}

temp->next = head;

}



void del_IN_cirlular(Node* head, int key)
{
Node* temp = head;
Node* prev = NULL;

while(temp->data!=key)
{
prev = temp;
temp = temp->next;
}
prev->next = temp->next;
delete temp;
temp = prev->next;



}

void print(Node* head)
{
Node* temp = head;
do {
cout<<temp->data<<"->";
temp = temp->next;
}while(temp!=head);
cout<<endl;


}


int main()
{


Node* head = NULL;


push(&head,7);
push(&head,6);
push(&head,5);
push(&head,4);
push(&head,3);
push(&head,2);
push(&head,1);
circular(head);
print(head);
del_IN_cirlular(head,5);
print(head);
}
62 changes: 62 additions & 0 deletions Find the middle Element of a linked list..cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#include<iostream>
using namespace std;

class Node{
public:
int data;
Node* next;

};
void push(Node**head, int val)
{

Node* new_node = new Node();
new_node->data = val;
new_node->next = *head;
*head = new_node;
}
int lenght(Node* head)
{
Node* tem = head;
int count =0;
while(tem!=NULL)
{
// cout<<"1";
count++;

tem = tem->next;

}
return count;



}
void dp(Node* head)
{
Node* temp = head;
while(temp!=NULL)
{
cout<<temp->data<<"->";
temp = temp->next;
}
cout<<"NULL\n";
int mid = lenght(head);
for(int i=0;i<mid/2;i++)
{
head = head->next;
}
cout<<head->data;
}

int main()
{
Node* head = NULL;
push(&head,9);
push(&head,4);
push(&head,6);
push(&head,5);
push(&head,3);
push(&head,2);
dp(head);
}
85 changes: 85 additions & 0 deletions Remove Duplicates in a Un-sorted Linked List..cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#include <bits/stdc++.h>
using namespace std;

class Node{
public:
int data;
Node* next;

};

void push(Node** head, int val)
{

Node* new_node = new Node();
new_node->data = val;

new_node->next = *head;
*head = new_node;

}

void removeDupplicat(Node* head)
{
Node* temp = head;
Node* ptr1;
Node* dubli;
while(temp!=NULL && temp->next!=NULL)

{

ptr1 = temp;

while(ptr1->next !=NULL)
{
if(temp->data == ptr1->next->data)
{
dubli = ptr1->next;
ptr1->next = ptr1->next->next;
delete (dubli);
}
else {
ptr1 = ptr1->next;
}
}
temp = temp->next;

}

}

void print(Node* head)
{

Node* temp = head;

while(temp!=NULL)
{
cout<<temp->data<<"->";
temp = temp->next;

}
cout<<"NULL"<<endl;


}

int main()
{


Node* head = NULL;


push(&head,5);
push(&head,6);
push(&head,5);
push(&head,2);
push(&head,3);
push(&head,2);
push(&head,5);

print(head);
removeDupplicat(head);
print(head);
}
87 changes: 87 additions & 0 deletions Remove Duplicates in a sorted Linked List.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
#include <bits/stdc++.h>
using namespace std;

class Node{
public:
int data;
Node* next;

};

void push(Node** head, int val)
{

Node* new_node = new Node();
new_node->data = val;

new_node->next = *head;
*head = new_node;


}

void removeDupplicat(Node* head)
{
Node* temp = head;
Node* next = NULL;


while(temp!=NULL)
{
if(temp->data == temp->next->data)
{
cout<<temp->data<<" "<<temp->next->data<<" \n";

next = temp->next->next;
free (temp->next);
temp->next = next;
}

temp = temp->next;

}





}



void print(Node* head)
{

Node* temp = head;

while(temp!=NULL)
{
cout<<temp->data<<"->";
temp = temp->next;

}
cout<<"NULL"<<endl;


}

int main()
{


Node* head = NULL;


push(&head,6);
push(&head,6);
push(&head,5);
push(&head,3);
push(&head,3);
push(&head,2);
push(&head,1);

print(head);
removeDupplicat(head);
print(head);

}
Loading