Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
32 changed files
with
1,685 additions
and
201 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
console.log('Hello world'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
int main (int argc, const char * argv[]) | ||
{ | ||
int i, j, n = 150, P[151] = { 0, 1 }, prime = 1; | ||
|
||
for ( i = 2; i <= n; ++i ) { | ||
P[i] = prime; | ||
for ( j = 2; j < i ; ++j ) { | ||
if ( i % j == 0 ) | ||
P[i] = 0; | ||
} | ||
} | ||
printf("Print prime numbers results:\n\n"); | ||
for (i = 2; i <= n ; ++i) { | ||
if ( P[i] != 0 ) | ||
printf("%i\n", i); | ||
} | ||
|
||
printf(" \n"); | ||
printf("Print prime numbers original program #results:\n\n"); | ||
//Original program referenced. | ||
int p, d, isPrime; | ||
for ( p = 2; p <= 150; ++p ) { | ||
isPrime = 1; | ||
for ( d = 2; d < p; ++d ) | ||
if ( p % d == 0 ) | ||
isPrime = 0; | ||
if ( isPrime != 0 ) | ||
NSLog (@"%i ", p); | ||
} | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#include <iostream> | ||
using namespace std; | ||
|
||
// A recursive binary search function. It returns | ||
// location of x in given array arr[l..r] is present, | ||
// otherwise -1 | ||
int binarySearch(int arr[], int l, int r, int x) | ||
{ | ||
if (r >= l) { | ||
int mid = l + (r - l) / 2; | ||
|
||
// If the element is present at the middle | ||
// itself | ||
if (arr[mid] == x) | ||
return mid; | ||
|
||
// If element is smaller than mid, then | ||
// it can only be present in left subarray | ||
if (arr[mid] > x) | ||
return binarySearch(arr, l, mid - 1, x); | ||
|
||
// Else the element can only be present | ||
// in right subarray | ||
return binarySearch(arr, mid + 1, r, x); | ||
} | ||
|
||
// We reach here when element is not | ||
// present in array | ||
return -1; | ||
} | ||
|
||
int main(void) | ||
{ | ||
int arr[] = { 2, 3, 4, 10, 40 }; | ||
int x = 10; | ||
int n = sizeof(arr) / sizeof(arr[0]); | ||
int result = binarySearch(arr, 0, n - 1, x); | ||
if(result!=-1) | ||
cout<<"Element is present at index " << result <<endl; | ||
else | ||
cout << "Element is not present " << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include <bits/stdc++.h> | ||
|
||
using namespace std; | ||
|
||
// Function to return gcd of two numbers a and b | ||
int gcd(int a, int b) | ||
{ | ||
if (a == 0) | ||
return b; | ||
return gcd(b % a, a); | ||
} | ||
|
||
// Driver Code | ||
int main() | ||
{ | ||
int a, b; | ||
cout<<"Enter any 2 numbers to find their gcd: "; | ||
cin>>a>>b; | ||
|
||
cout << "GCD(" << a << ", " << b << ") = " << gcd(a, b) << endl; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// C++ program to detect and remove loop | ||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
struct Node { | ||
int key; | ||
struct Node* next; | ||
}; | ||
|
||
Node* newNode(int key) | ||
{ | ||
Node* temp = new Node; | ||
temp->key = key; | ||
temp->next = NULL; | ||
return temp; | ||
} | ||
|
||
void printList(Node* head) | ||
{ | ||
while (head != NULL) { | ||
cout << head->key << " "; | ||
head = head->next; | ||
} | ||
cout << endl; | ||
} | ||
|
||
|
||
void detectAndRemoveLoop(Node* head) | ||
{ | ||
// If list is empty or has only one node | ||
// without loop | ||
if (head == NULL || head->next == NULL) | ||
return; | ||
|
||
Node *slow = head, *fast = head; | ||
|
||
slow = slow->next; | ||
fast = fast->next->next; | ||
|
||
while (fast && fast->next) { | ||
if (slow == fast) | ||
break; | ||
slow = slow->next; | ||
fast = fast->next->next; | ||
} | ||
|
||
if (slow == fast) { | ||
slow = head; | ||
while (slow->next != fast->next) { | ||
slow = slow->next; | ||
fast = fast->next; | ||
} | ||
|
||
fast->next = NULL; /* remove loop */ | ||
} | ||
} | ||
|
||
int main() | ||
{ | ||
Node* head = newNode(50); | ||
head->next = head; | ||
head->next = newNode(20); | ||
head->next->next = newNode(15); | ||
head->next->next->next = newNode(4); | ||
head->next->next->next->next = newNode(10); | ||
|
||
head->next->next->next->next->next = head->next->next; | ||
|
||
detectAndRemoveLoop(head); | ||
|
||
printf("Linked List after removing loop \n"); | ||
printList(head); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,179 @@ | ||
#include<iostream> | ||
#include<cstring> | ||
#include<fstream> | ||
|
||
using namespace std; | ||
|
||
|
||
class Stud; | ||
class MyException | ||
{ | ||
char str1[50]; | ||
int what; | ||
|
||
public: | ||
MyException() | ||
{ | ||
*str1 =0; | ||
what =0; | ||
} | ||
MyException (const char s[], int x) | ||
{ | ||
strcpy(str1,s); | ||
what = x; | ||
|
||
} | ||
void printInfo(MyException e) | ||
{ | ||
cout<<e.str1; | ||
cout<<e.what; | ||
|
||
} | ||
//friend class Stud; | ||
}; | ||
|
||
class Stud | ||
{ | ||
int rollNo; | ||
int Age; | ||
int yoj; | ||
public: | ||
void setInfo(int x, int y, int z) | ||
{ | ||
rollNo =x; | ||
Age =y; | ||
yoj =z; | ||
} | ||
void displayInfo() | ||
{ | ||
cout<<"\t"<<rollNo; | ||
cout<<"\t"<<Age; | ||
cout<<"\t"<<yoj<<endl; | ||
} | ||
|
||
}; | ||
Stud createRecord(); | ||
void displayColHead() | ||
{ | ||
cout<<"\t rollNo"; | ||
cout<<"\t Age"; | ||
cout<<"\t yoj"<<endl; | ||
|
||
} | ||
void menu() | ||
{ | ||
cout<<"1.Creation "<<endl; | ||
cout<<"2.Display "<<endl; | ||
cout<<"3.Appending "<<endl; | ||
|
||
|
||
} | ||
void createFile() | ||
{ | ||
Stud s; | ||
int opt; | ||
ofstream out; | ||
out.open("stud.dat",ios::out|ios::binary); | ||
|
||
while(opt) | ||
{ | ||
s=createRecord(); | ||
out.write((char*)&s,sizeof(s)); | ||
cout<<"Any more records?(1/0)"; | ||
cin>>opt; | ||
|
||
} | ||
out.close(); | ||
|
||
} | ||
|
||
Stud createRecord() | ||
{ | ||
int a,b,c; | ||
int flag=0; | ||
Stud s; | ||
while(!flag) | ||
{ | ||
try | ||
{ | ||
flag=1; | ||
cout<<" enter values for roll no and age and yob: "<<endl; | ||
cin>>a; | ||
cin>>b; | ||
cin>>c; | ||
|
||
if (a<=0) | ||
throw MyException("Roll No cannot be negative....",a); | ||
if (b<15) | ||
throw MyException("Age cannot be less than 15::", b); | ||
|
||
if (c >2019) | ||
throw MyException("jOINING Year Cannot be greater than current year :: ",c); | ||
} | ||
catch(MyException e) | ||
{ | ||
e.printInfo(e); | ||
flag =0; | ||
} | ||
if (flag==1){ | ||
s.setInfo(a,b,c); | ||
return s; | ||
} | ||
} | ||
} | ||
|
||
void displayFile() | ||
{ | ||
Stud s; | ||
ifstream in; | ||
in.open("stud.dat",ios::in|ios::binary); | ||
|
||
in.read((char *)&s,sizeof(s)); | ||
while(!in.eof()) | ||
{ | ||
s.displayInfo(); | ||
in.read((char *)&s,sizeof(s)); | ||
} | ||
} | ||
|
||
void appendRecord() | ||
{ | ||
Stud s; | ||
fstream out; | ||
out.open("stud.dat",ios::app|ios::out|ios::binary); | ||
s=createRecord(); | ||
out.write((char *)&s,sizeof(s)); | ||
out.close(); | ||
} | ||
|
||
|
||
int main() | ||
{ | ||
|
||
int opt=1; | ||
while(opt) | ||
{ | ||
menu(); | ||
cout<<"Enter ur option..."; | ||
cin>>opt; | ||
if (opt==1) | ||
{ | ||
createFile(); | ||
cout<<"File created successfully ....."<<endl; | ||
} | ||
if (opt==2) | ||
{ | ||
displayFile(); | ||
cout<<"File displayed successfully ....."<<endl; | ||
} | ||
if (opt==3) | ||
{ | ||
appendRecord(); | ||
cout<<"File appended successfully ....."<<endl; | ||
} | ||
} | ||
} | ||
|
||
|
||
|
||
|
Oops, something went wrong.