Skip to content

Linked List done #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
64 changes: 64 additions & 0 deletions akashmartule/Linked List/Deletion.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#include<bits\stdc++.h>
using namespace std;

struct Node
{
int data;
struct Node* next;
}*first= NULL;

void create(int A[],int n){
int i;
struct Node *t, *last;
first=new Node;
first->data=A[0];
first->next=NULL;
last=first;

for(i=1;i<n;i++){
t=new Node;
t->data=A[i];
t->next=NULL;
last->next=t;
last=t;
}
}

void Display(struct Node *p){
while(p!=NULL){
cout<<p->data<<" ";
p=p->next;
}
}
void Delete(struct Node *p, int index)
{
struct Node *q=NULL;
int x= -1,i;
if(index==1){
q=first;
x=first->data;
first=first->next;
delete q;

}
else{
q=p;
p=p->next;
q->next=p->next;
x=p->data;
delete p;

}



}

int main()
{
int A[]={6,5,4,3,2};
create(A,5);
// cout<<Delete<<first,3;
Delete(first,3);
Display(first);
}
Binary file added akashmartule/Linked List/Deletion.exe
Binary file not shown.
52 changes: 52 additions & 0 deletions akashmartule/Linked List/Display.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include <iostream>
using namespace std;

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

int main() {

int A[] = {3, 5, 7, 10, 15};

Node* head = new Node;

Node* temp;
Node* last;

head->data = A[0];
head->next = nullptr;
last = head;

// Create a Linked List
for (int i=1; i<sizeof(A)/sizeof(A[0]); i++){

// Create a temporary Node
temp = new Node;

// Populate temporary Node
temp->data = A[i];
temp->next = nullptr;

// last's next is pointing to temp
last->next = temp;
last = temp;
}

// Display Linked List
Node* p = head;

while (p != nullptr){
cout << p->data << " -> " << flush;
p = p->next;

// recurssive
// p=p->next;
// cout << p->data << " -> " << flush;

}

return 0;
}
58 changes: 58 additions & 0 deletions akashmartule/Linked List/MAX_Element.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include<bits\stdc++.h>
using namespace std;
struct Node
{
int data;
struct Node* next;
}*first= NULL;
void create(int A[],int n)
{
int i;
struct Node *t, *last;
first= new Node;
first->data=A[0];
first->next=NULL;
last=first;

for(i=1;i<n;i++){
t=new Node;
t->data=A[i];
t->next=NULL;
last->next=t;
last=t;

}

}

int Max(struct Node *p)
{
int max= INT_MIN;
while(p!=NULL)
{
if(p->data>max)
max =p -> data;
p=p->next;
}
return max;

}
void Display(struct Node *p)
{
while(p!=NULL)
{
cout<<p->data<<" ";
p=p->next;
}
}


int main()
{
int A[]= {4,5,6,7,8};
create(A,5);
Display(first);
cout<<"Maximum node in linked list is: "<<Max(first);
return 0;

}
Binary file added akashmartule/Linked List/MAX_Element.exe
Binary file not shown.
60 changes: 60 additions & 0 deletions akashmartule/Linked List/Max.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#include<bits\stdc++.h>
using namespace std;
struct Node
{
int data;
struct Node* next;
}*first=NULL;

void create(int A[],int n)
{
int i;
struct Node *t, *last;
first=new Node;
first->data=A[0];
first->next=NULL;
last=first;

for(i=1;i<n;i++){
t=new Node;
t->data=A[i];
t->next=NULL;
last->next=t;
last=t;
}
}

void Display(struct Node *p)
{
while(p!=NULL)
{
cout<<p->data<<" ";
p=p->next;
}
}
int Max(struct Node*p)
{
int max=INT_MIN;
while(p!=NULL)
{
if(p->data>max)
max=p->data;
p=p->next;
}
return max;
}

int main()
{



int A[]={1,2,3,4,5,6};
create(A,6);
Display(first);
cout<<"maximum element is: "<<Max(first);
return 0;


}

Binary file added akashmartule/Linked List/Max.exe
Binary file not shown.
46 changes: 46 additions & 0 deletions akashmartule/Linked List/Searching.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include<iostream>
using namespace std;

struct Node
{
int data;
struct Node* next;

}*first=NULL;
void create(int A[],int n)
{
int i;
struct Node *t,*last;
first=new Node;
first->data=A[0];
first->next=NULL;
last=first;

for(i=1;i<n;i++)
{
t=new Node;
t->data=A[i];
t->next=NULL;
last->next=t;
last=t;
}

};
Node* Lsearch(struct Node *p, int key)
{
while(p!=NULL)
{
if(key==p->data);
return p;
p=p->next;
}
return NULL;
}
int main()
{
int A[]={5,6,8,7,3,4};
create(A,6);
Lsearch(first,7);
return 0;

}
Binary file added akashmartule/Linked List/Searching.exe
Binary file not shown.
Binary file added akashmartule/Linked List/aaaaa.exe
Binary file not shown.
Binary file added akashmartule/Linked List/count_node.exe
Binary file not shown.
55 changes: 55 additions & 0 deletions akashmartule/Linked List/count_sum_node.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#include<bits\stdc++.h>
using namespace std;
class Node
{
public:
int data;
Node* next;
};
void push(Node** head_ref, int new_data)
{
Node* new_node= new Node();
new_node->data=new_data;
new_node->next= (*head_ref);
(*head_ref)=new_node;

}
int getCount(Node* head)
{
int count=0;
Node* current=head;
while(current !=NULL)
{
count++;
current=current->next;
}
return count;
}
int getsum(Node* head)
{
int sum=0;
Node* current=head;
while(current !=NULL ){
sum=sum + current->data;
current=current->next;
}
return sum;
}

int main()
{
Node*head =NULL;

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

cout<<"Count of nodes is"<<getCount(head)<<endl;


cout<<"Sum of linked list: "<<getsum(head)<<endl;
return 0;
}
43 changes: 43 additions & 0 deletions akashmartule/Linked List/createLL.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <bits/stdc++.h>
using namespace std;

class Node {
public:
int data;
Node* next;
};
void printList(Node* n)
{

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

// Program to create a simple linked
// list with 3 nodes
int main()
{
Node* head = NULL;
Node* second = NULL;
Node* third = NULL;

// allocate 3 nodes in the heap
head = new Node();
second = new Node();
third = new Node();

head->data=1;
head->next=second;

second->data=2;
second->next=third;

third->data=3;
third->next=NULL;

printList(head);
return 0;
}
Loading