Skip to content

Commit 87b86a0

Browse files
authored
Add files via upload
1 parent fd1b66a commit 87b86a0

File tree

100 files changed

+1272
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

100 files changed

+1272
-0
lines changed

List_Delete_Single.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
void deleteNode(Node *ptr)
2+
{
3+
//creating temporary pointer
4+
Node *temp;
5+
//Pointing temp to link part of current node i.e. next node
6+
temp=ptr->link;
7+
//copy data and link part of next node to current node
8+
ptr->data=temp->data;
9+
//point current node to link part of next node
10+
ptr->link=temp->link;
11+
//Delete current node
12+
free(temp);
13+
14+
}
15+

a.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
i am a good boy

abc.png

5.72 KB
Loading

anagram0(n).cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include<iostream>
2+
using namespace std;
3+
int anagram(string s1,string s2)
4+
{
5+
int first[26] = {0}, second[26] = {0}, c = 0;
6+
while (s1[c] != '\0')
7+
{
8+
first[s1[c]-'a']++;
9+
c++;
10+
}
11+
c = 0;
12+
while (s2[c] != '\0')
13+
{
14+
second[s2[c]-'a']++;
15+
c++;
16+
}
17+
// Comparing frequency of characters
18+
for (c = 0; c < 26; c++)
19+
{
20+
if (first[c] != second[c])
21+
return 0;
22+
else
23+
{cout<<first[c];
24+
cout<<second[c]<<"\n";}
25+
26+
}
27+
28+
return 1;
29+
}
30+
int main()
31+
{
32+
string s1,s2;
33+
cin>>s1>>s2;
34+
if(anagram(s1,s2)==1)
35+
cout<<"anagram";
36+
else
37+
cout<<"not anagrma";
38+
return 0;
39+
}

anagram0(n).exe

1 MB
Binary file not shown.

anagram0(n).o

2.97 KB
Binary file not shown.

anagramO(nlogn).cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include<iostream>
2+
#include<string>
3+
#include<algorithm>
4+
using namespace std;
5+
6+
bool isAnagram(string a,string b){
7+
int n1,n2;
8+
n1=a.length();
9+
n2=b.length();
10+
if(n1!=n2)
11+
return false;
12+
13+
sort(a.begin(),a.end());
14+
sort(b.begin(),b.end());
15+
for(int i=0;i<n1;i++)
16+
{if(a[i]!=b[i])
17+
return false;
18+
}
19+
20+
return true;
21+
}
22+
int main()
23+
{
24+
string a,b;
25+
cin>>a>>b;
26+
bool ans;
27+
ans=isAnagram(a,b);
28+
if(ans==1)
29+
cout<<"anagram";
30+
else
31+
cout<<"not anagram";
32+
return 0;
33+
}

anagramO(nlogn)quickSort.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include<iostream>
2+
#include<string>
3+
#include<algorithm>
4+
using namespace std;
5+
6+
bool isAnagram(string a,string b){
7+
int n1,n2;
8+
n1=a.length();
9+
n2=b.length();
10+
if(n1!=n2)
11+
return false;
12+
13+
sort(a.begin(),a.end());
14+
sort(b.begin(),b.end());
15+
for(int i=0;i<n1;i++)
16+
{if(a[i]!=b[i])
17+
return false;
18+
}
19+
20+
return true;
21+
}
22+
int main()
23+
{
24+
string a,b;
25+
cin>>a>>b;
26+
bool ans;
27+
ans=isAnagram(a,b);
28+
if(ans==1)
29+
cout<<"anagram";
30+
else
31+
cout<<"not anagram";
32+
return 0;
33+
}

anagramO(nlogn)quickSort.exe

1.01 MB
Binary file not shown.

anagramO(nlogn)quickSort.o

22.9 KB
Binary file not shown.

b.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this is file b

basic linkedlist.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include<iostream>
2+
using namespace std;
3+
struct node{
4+
int data;
5+
node* next;
6+
};
7+
node* head=NULL;
8+
int main(){
9+
node* ptr= new node();
10+
ptr->data=5;
11+
ptr->next=NULL;
12+
head=ptr;
13+
delete ptr;
14+
cout<<"data in 1st created node is "<<head->data<<"\n";
15+
cout<<"next value address in 1st created node is "<<head->next<<"\n";
16+
cout<<"ptr values after its deleted "<<ptr->data<<"\n"<<"next value of ptr aftr deletion"<<ptr->next;
17+
//it frees the memory but still keeps record of the previous values
18+
return 0;
19+
20+
}

basic linkedlist.exe

1 MB
Binary file not shown.

basic linkedlist.o

1.95 KB
Binary file not shown.

binarySearch.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include<stdio.h>
2+
int binarySearch(int Arr[], int n, int target) {
3+
4+
//set stating and ending index
5+
int start = 0, ending = n-1;
6+
7+
while(start <= ending) {
8+
// take mid of the list
9+
int mid = (start + ending) / 2;
10+
11+
// we found a match
12+
if(Arr[mid] == target) {
13+
return mid;
14+
}
15+
// go on right side
16+
else if(Arr[mid] < target) {
17+
start = mid + 1;
18+
}
19+
// go on left side
20+
else {
21+
ending = mid - 1;
22+
}
23+
}
24+
// element is not present in list
25+
return -1;
26+
}
27+
int main()
28+
{
29+
int A[]={1,4,5,6,8,9,21};
30+
int x;
31+
printf("enter the target element\n");
32+
scanf("%d",&x);
33+
int index=binarySearch(A,7,x);
34+
if(index!=-1){
35+
printf("index at %d",index+1);
36+
}
37+
else
38+
printf("out of bound");
39+
return 0;
40+
}

binarySearch.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

binarySearch.exe

27.6 KB
Binary file not shown.

binarySearch.o

1.06 KB
Binary file not shown.

bubbleSort.cpp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include<iostream>
2+
using namespace std;
3+
void bubbleSort(int A[],int n)
4+
{
5+
for(int k=1;k<=n-1;k++){
6+
int flag=0;
7+
for(int i=0;i<=n-k-1;i++){
8+
if(A[i]>A[i+1])
9+
{
10+
//swap(A[i],A[i+1])
11+
int temp=A[i];
12+
A[i]=A[i+1];
13+
A[i+1]=temp;
14+
flag=1;
15+
}
16+
}
17+
if(flag==0)
18+
break;
19+
}
20+
}
21+
22+
23+
int main()
24+
{
25+
int A[]={4,5,8,7,9,3,2};
26+
bubbleSort(A,7);
27+
for(int i=0;i<7;i++)
28+
cout<<A[i]<<" ";
29+
}

bubbleSort.exe

1020 KB
Binary file not shown.

bubbleSort.o

1.61 KB
Binary file not shown.

c.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this is file c

d.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
this is file d

decimal2binary.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include<iostream>
2+
using namespace std;
3+
int main()
4+
{
5+
int n,r,base=1,sum=0;
6+
cin>>n;
7+
while(n!=0)
8+
{
9+
r=n%2;
10+
sum+=r*base;
11+
n/=2;
12+
base*=10;
13+
}
14+
cout<<sum;
15+
return 0;
16+
}

decimal2binary.exe

1020 KB
Binary file not shown.

decimal2binary.o

1.25 KB
Binary file not shown.

deletion in linkedlist.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#include<iostream>
2+
#include<cstdlib>
3+
using namespace std;
4+
struct node{
5+
int data;
6+
node* next;
7+
};
8+
node* head=NULL;
9+
10+
void deletebeg(){
11+
if(head==NULL){
12+
cout<<"list is empty";
13+
}
14+
else{
15+
node* ptr=head;
16+
head=head->next;
17+
free(ptr);
18+
}
19+
}
20+
void deleteend(){
21+
if(head==NULL)//no element
22+
cout<<"empty list";
23+
else if(head->next==NULL){//if only 1 element present
24+
node* ptr=head;
25+
head=NULL;
26+
free(ptr);
27+
}
28+
else{
29+
node* ptr=head;
30+
node* prev;//creating a pointer to previous node, so that we can delete the last node
31+
while(ptr->next!=NULL){
32+
prev=ptr;
33+
ptr=ptr->next;
34+
}
35+
prev->next=NULL;
36+
free(ptr);
37+
}
38+
}
39+
void insertbeg(int d){
40+
node* ptr=new node();
41+
ptr->data=d;
42+
ptr->next=head;
43+
head=ptr;
44+
}
45+
void insertend(int d){
46+
node* ptr=new node();
47+
ptr->data=d;
48+
ptr->next=NULL;
49+
if(head==NULL)
50+
head=ptr;
51+
else{
52+
node* temp=head;
53+
while(temp->next!=NULL){
54+
temp=temp->next;
55+
}
56+
temp->next=ptr;
57+
}
58+
}
59+
void display(){
60+
node* temp=head;
61+
while(temp!=NULL){
62+
cout<<temp->data<<" ";
63+
temp=temp->next;
64+
}
65+
}
66+
int main(){
67+
insertbeg(8);
68+
insertbeg(7);
69+
insertend(9);
70+
insertend(10);
71+
insertend(12);
72+
display();
73+
cout<<"\n";
74+
deletebeg();
75+
deleteend();
76+
display();
77+
return 0;
78+
}

deletion in linkedlist.exe

1020 KB
Binary file not shown.

deletion in linkedlist.o

2.31 KB
Binary file not shown.

0 commit comments

Comments
 (0)