Skip to content
This repository has been archived by the owner on Oct 4, 2022. It is now read-only.

hack #2095

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

hack #2095

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
2 changes: 1 addition & 1 deletion C++/Algorithms/Sorting/BubbleSort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ int main() {
int arr[13] = {5, 4, 9, 123, 58, 37, 324, 444, 699, 347, -1, 0, 200};
int n = sizeof(arr) / sizeof(arr[0]);

bubblesort(arr, n, compare);
bubblesort(arr, n);

for (int i = 0; i < n; i++)
printf("%d ", arr[i]);
Expand Down
187 changes: 187 additions & 0 deletions C++/Data Structure/reverseLinkedlist.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
#include<bits/stdc++.h>
using namespace std;
class Node{
public:
int data;
Node*next;
Node(int data){
this->data=data;
next=NULL;
}
};
class Pair{
public:
Node* head;
Node* tail;
};
Pair reverseLL_2(Node* head){
if(head==NULL || head->next==NULL){

Pair an;
an.head=head;
an.tail=head;
return an;
}
Pair ans=reverseLL_2(head->next);
ans.tail->next=head;
head->next=NULL;
Pair an;
an.head=ans.head;
an.tail=head;
return an;

}
Node* reverseLL_Better(Node*head){
return reverseLL_2(head).head;
}
Node* enterElement(Node* head){

int data;
cin>>data;
Node* newNode=new Node(data);
if(head==NULL){
head=newNode;
return head;
}
Node* temp=head;
while (temp->next!=NULL)
{
temp=temp->next;
}
temp->next=newNode;
return head;


}
Node* insertNode(Node* head){
cout<<"Enter the lenght of linked list you want to reverse"<<endl;
int lenght;
cin>>lenght;
cout<<"Enter data"<<endl;
for (int i = 0; i < lenght; i++)
{
head=enterElement(head);
}
return head;

}
void print(Node *head){
while (head!=NULL)
{
cout<<head->data<<" ";
head=head -> next;
}
cout<<endl;
}
Node* reverseList(Node* head){
if(head==NULL || head->next==NULL){
return head;
}
Node* ans=reverseList(head->next);
Node* temp=ans;
while (temp->next!=NULL)
{
temp=temp->next;
}
temp->next=head;
head->next=NULL;
return ans;

}
Node* reverseList_3(Node* head){
if(head==NULL || head->next==NULL){
return head;
}
Node* ans=reverseList(head->next);
Node* tail=head->next;
tail->next=head;
head->next=NULL;
return ans;

}
Node* reverseLL_4(Node* head){
Node* cur=head;
Node* pre=NULL;
Node* next=cur;
if(head==NULL || head->next==NULL){
return head;
}
while (cur!=NULL)
{
next=cur->next;
cur->next=pre;
pre=cur;
cur=next;

}
head=pre;
return head;

}
int main()
{
Node* head=NULL;
head=insertNode(head);
cout<<"The entered linked list is "<<endl;
print(head);
back:
int input;
cout<<"Enter the method you want to use for reverse linkedlist"<<endl;
cout<<"Enter 1 for using recursion with time complixity of n^2"<<endl;
cout<<"Enter 2 for using recursion with time complixity of n and pair of return type using class"<<endl;
cout<<"Enter 3 for using recursion with time complixity of n using tail concept"<<endl;
cout<<"Enter 4 for using Iterative "<<endl;
cin>>input;
switch (input)
{
case 1:
{

head=reverseList(head);
cout<<"The reverse linked list is "<<endl;
print(head);
goto back;
break;
}
case 2:
{

head=reverseLL_Better(head);
cout<<"The reverse linked list is "<<endl;
print(head);
goto back;
break;
}
case 3:
{

head=reverseList_3(head);
cout<<"The reverse linked list is "<<endl;
print(head);
goto back;
break;
}
case 4:
{

head=reverseLL_4(head);
cout<<"The reverse linked list is "<<endl;
print(head);
goto back;
break;
}
default:
break;
}










return 0;
}
4 changes: 2 additions & 2 deletions Java/Algorithms/Arrays/PrefixSum Technique/ThreeEqualSum.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public static boolean checkThreeEqualSum(int[] arr,int n){
splitCount++;
}

return splitCount==3;
return splitCount;
}

public static void main(String args[]){
int arr[] = {2,2,2};
System.out.println(checkThreeEqualSum(arr,arr.length));
}
}
}
4 changes: 2 additions & 2 deletions Java/Algorithms/BinarySearch/BinarySearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static int binarySearch(int[] sortedArr,int target){
return mid;
}
}
return -1;
;

}

Expand Down Expand Up @@ -69,4 +69,4 @@ static int descendingBinarySearch(int[] arr,int target){
*/


}
}