diff --git a/akashmartule/Linked List/Deletion.cpp b/akashmartule/Linked List/Deletion.cpp new file mode 100644 index 0000000..3b9bd8f --- /dev/null +++ b/akashmartule/Linked List/Deletion.cpp @@ -0,0 +1,64 @@ +#include +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;idata=A[i]; + t->next=NULL; + last->next=t; + last=t; + } +} + +void Display(struct Node *p){ + while(p!=NULL){ + cout<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< +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; idata = 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; +} \ No newline at end of file diff --git a/akashmartule/Linked List/MAX_Element.cpp b/akashmartule/Linked List/MAX_Element.cpp new file mode 100644 index 0000000..1061dbd --- /dev/null +++ b/akashmartule/Linked List/MAX_Element.cpp @@ -0,0 +1,58 @@ +#include +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;idata=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<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: "< +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;idata=A[i]; + t->next=NULL; + last->next=t; + last=t; + } +} + +void Display(struct Node *p) +{ + while(p!=NULL) + { + cout<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: "< +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;idata=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; + +} \ No newline at end of file diff --git a/akashmartule/Linked List/Searching.exe b/akashmartule/Linked List/Searching.exe new file mode 100644 index 0000000..8f5fd1c Binary files /dev/null and b/akashmartule/Linked List/Searching.exe differ diff --git a/akashmartule/Linked List/aaaaa.exe b/akashmartule/Linked List/aaaaa.exe new file mode 100644 index 0000000..d904d24 Binary files /dev/null and b/akashmartule/Linked List/aaaaa.exe differ diff --git a/akashmartule/Linked List/count_node.exe b/akashmartule/Linked List/count_node.exe new file mode 100644 index 0000000..480b7cc Binary files /dev/null and b/akashmartule/Linked List/count_node.exe differ diff --git a/akashmartule/Linked List/count_sum_node.cpp b/akashmartule/Linked List/count_sum_node.cpp new file mode 100644 index 0000000..7ae1120 --- /dev/null +++ b/akashmartule/Linked List/count_sum_node.cpp @@ -0,0 +1,55 @@ +#include +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"< +using namespace std; + +class Node { +public: + int data; + Node* next; +}; +void printList(Node* n) + { + + while(n!=NULL) + { + cout<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; +} \ No newline at end of file diff --git a/akashmartule/Linked List/create_display.cpp b/akashmartule/Linked List/create_display.cpp new file mode 100644 index 0000000..43e9126 --- /dev/null +++ b/akashmartule/Linked List/create_display.cpp @@ -0,0 +1,46 @@ +#include +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<data<<" "; + p=p->next; + } +} + + + + +int main() +{ + + int A[]={1,2,3,4,5,6}; + create(A,6); + + Display(first); +} \ No newline at end of file diff --git a/akashmartule/Linked List/create_display.exe b/akashmartule/Linked List/create_display.exe new file mode 100644 index 0000000..3090d3a Binary files /dev/null and b/akashmartule/Linked List/create_display.exe differ diff --git a/akashmartule/Linked List/create_linked_usingInsert.cpp b/akashmartule/Linked List/create_linked_usingInsert.cpp new file mode 100644 index 0000000..c732c22 --- /dev/null +++ b/akashmartule/Linked List/create_linked_usingInsert.cpp @@ -0,0 +1,45 @@ +#include +using namespace std; + +struct Node +{ + int data; + struct Node* next; +}*first=NULL; + +int insert(struct Node* p, int index,int x) +{ + struct Node *t; + int i; + t=new Node; + t->data=x; + + if(index==0){ + t->next=first; + first=t; + } + else{ + for(i=0;inext; + t->next=p->next; + p->next=t; + } + } +} +void Display(struct Node* p){ + while(p!=NULL){ + cout<data<<" "; + p=p->next; + } +} + +int main() +{ + insert(first,0,45); + insert(first,1,455); + insert(first,2,46); + insert(first,0,47); + Display(first); + return 0; +} + diff --git a/akashmartule/Linked List/create_linked_usingInsert.exe b/akashmartule/Linked List/create_linked_usingInsert.exe new file mode 100644 index 0000000..a48162d Binary files /dev/null and b/akashmartule/Linked List/create_linked_usingInsert.exe differ diff --git a/akashmartule/Linked List/createsonal.cpp b/akashmartule/Linked List/createsonal.cpp new file mode 100644 index 0000000..6b7a80d --- /dev/null +++ b/akashmartule/Linked List/createsonal.cpp @@ -0,0 +1,67 @@ +#include +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;idata=A[i]; + t->next=NULL; + last->next=t; + last=t; +} +} +void Insert(struct Node *p, int Index, int x) +{ + struct Node *t; + int i; + t=new Node; + t->data=x; + + if(Index==0){ + t->next=first; + first=t; + } + else{ + for(i=0;inext; + t->next=p->next; + p->next=t; + } + } + +} + +void Print(struct Node *p) +{ + + while(p!=NULL){ + cout<data<<" "; + p=p->next; + } + +} + + +int main() +{ + int A[]={1,2,3,4,5}; + create(A,5); + Insert(first,4,65); + Print(first); + + +} \ No newline at end of file diff --git a/akashmartule/Linked List/createsonal.exe b/akashmartule/Linked List/createsonal.exe new file mode 100644 index 0000000..14c21ee Binary files /dev/null and b/akashmartule/Linked List/createsonal.exe differ diff --git a/akashmartule/Linked List/insert_node.cpp b/akashmartule/Linked List/insert_node.cpp new file mode 100644 index 0000000..bd839cd --- /dev/null +++ b/akashmartule/Linked List/insert_node.cpp @@ -0,0 +1,65 @@ +#include +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<data<<" "; + p=p->next; + } +} +void Insert(struct Node *p,int index,int x) +{ + struct Node *t; + int i; + t=new Node; + t->data=x; + + if(index == 0) + { + t->next=first; + first=t; + } + else + { + for(i=0;inext; + t->next=p->next; + p->next=t; + + } +} + +int main() +{ + + int A[]={1,2,3,4,5,6}; + create(A,6); + Insert(first,4,555555); + + Display(first); +} \ No newline at end of file diff --git a/akashmartule/Linked List/insert_node.exe b/akashmartule/Linked List/insert_node.exe new file mode 100644 index 0000000..a1f9f77 Binary files /dev/null and b/akashmartule/Linked List/insert_node.exe differ diff --git a/akashmartule/Linked List/insertion.exe b/akashmartule/Linked List/insertion.exe new file mode 100644 index 0000000..d4b8e9f Binary files /dev/null and b/akashmartule/Linked List/insertion.exe differ diff --git a/akashmartule/Linked List/jsDBE.exe b/akashmartule/Linked List/jsDBE.exe new file mode 100644 index 0000000..da6dda8 Binary files /dev/null and b/akashmartule/Linked List/jsDBE.exe differ diff --git a/akashmartule/Linked List/merging.cpp b/akashmartule/Linked List/merging.cpp new file mode 100644 index 0000000..9631f54 --- /dev/null +++ b/akashmartule/Linked List/merging.cpp @@ -0,0 +1,98 @@ +#include +using namespace std; +struct Node +{ + int data; + struct Node *next; +}*first=NULL,*second=NULL,*third=NULL; + +void create1(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;idata=A[i]; + t->next=NULL; + last->next=t; + last=t; + } +} +void create2(int A[],int n){ + int i; + struct Node *t, *last; + second=new Node; + second->data=A[0]; + second->next=NULL; + last=second; + + for(i=1;idata=A[i]; + t->next=NULL; + last->next=t; + last=t; + } +} + +void Display( struct Node *p){ + while(p!=NULL) + { + cout<data<<" "; + p=p->next; + } +} +void Merge(struct Node *p, struct Node *q) +{ + struct Node *last; + if(p->data < q->data) + { + third=last=p; + p=p->next; + third->next=NULL; + } + else{ + third=last=q; + q=q->next; + third->next=NULL; + } + + while(p!=NULL && q!=NULL) + { + if(p->data < q->data){ + last->next=p; + last=p; + p=p->next; + last->next=NULL; + } + else{ + last->next=q; + last=q; + q=q->next; + last->next=NULL; + } + if(p!=NULL){ + last->next=p; + } + if(q!=NULL){ + last->next=q; + } + } + +} + +int main() +{ + int A[]={5,15,25,35,45}; + int B[]={10,20,30,40,50}; + + create1(A,5); + create2(B,5); + Merge(first,second); + Display(third); + return 0; +} \ No newline at end of file diff --git a/akashmartule/Linked List/merging.exe b/akashmartule/Linked List/merging.exe new file mode 100644 index 0000000..a080de2 Binary files /dev/null and b/akashmartule/Linked List/merging.exe differ diff --git a/akashmartule/Linked List/tempCodeRunnerFile.cpp b/akashmartule/Linked List/tempCodeRunnerFile.cpp new file mode 100644 index 0000000..c9fb739 --- /dev/null +++ b/akashmartule/Linked List/tempCodeRunnerFile.cpp @@ -0,0 +1 @@ +Insert(first,4,65); \ No newline at end of file