Skip to content

Commit

Permalink
Added Selection sort in java
Browse files Browse the repository at this point in the history
  • Loading branch information
shibin340 committed Oct 18, 2020
1 parent 354e735 commit 63c2406
Show file tree
Hide file tree
Showing 9 changed files with 348 additions and 350 deletions.
50 changes: 25 additions & 25 deletions C/HarshadNumber.cpp
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
#include<iostream>
using namespace std;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int num,temp;
cin>>num;
temp=num;
int sum=0;
while(temp!=0)
{
int x=temp%10;
sum=sum+x;
temp/=10;
}
if(num%sum==0)
{
cout<<"Harshad Number";
}
else
cout<<"Not a Harshad NUmber";
return 0;
}
#include<iostream>
using namespace std;

int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int num,temp;
cin>>num;
temp=num;
int sum=0;
while(temp!=0)
{
int x=temp%10;
sum=sum+x;
temp/=10;
}
if(num%sum==0)
{
cout<<"Harshad Number";
}
else
cout<<"Not a Harshad NUmber";
return 0;
}
37 changes: 0 additions & 37 deletions C/is binary number a multiple of 3?

This file was deleted.

64 changes: 32 additions & 32 deletions C/knapsack.cpp
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
#include <bits/stdc++.h>
#include<vector>
using namespace std;

int max(int a, int b) { return (a > b) ? a : b; }

int knapSack(int W, int wt, int val, int n)
{

if (n == 0 || W == 0)
return 0;

if (wt[n] > W)
return knapSack(W, wt, val, n - 1);

else
return max(
val[n] + knapSack(W - wt[n],
wt, val, n - 1),
knapSack(W, wt, val, n - 1));
}

int main()
{

int val,wt;
cin>>val>>wt;
int W = 400;
int n = sizeof(val) / sizeof(val[0]);
cout << knapSack(W, wt, val, n);
return 0;
}
#include <bits/stdc++.h>
#include<vector>
using namespace std;

int max(int a, int b) { return (a > b) ? a : b; }

int knapSack(int W, int wt, int val, int n)
{

if (n == 0 || W == 0)
return 0;

if (wt[n] > W)
return knapSack(W, wt, val, n - 1);

else
return max(
val[n] + knapSack(W - wt[n],
wt, val, n - 1),
knapSack(W, wt, val, n - 1));
}

int main()
{

int val,wt;
cin>>val>>wt;
int W = 400;
int n = sizeof(val) / sizeof(val[0]);
cout << knapSack(W, wt, val, n);
return 0;
}
200 changes: 100 additions & 100 deletions C/mainq.c
Original file line number Diff line number Diff line change
@@ -1,100 +1,100 @@
#include <stdio.h>

#define MAX 50
int q[MAX];
int rear = - 1;
int front = - 1;
void insert()
{
int add_item;
if (rear == MAX - 1)
printf("Queue Overflow \n");
else
{
if (front == - 1)
front = 0;
printf("Inset the element in queue : ");
scanf("%d", &add_item);
rear = rear + 1;
q[rear] = add_item;
}
}

void delete()
{
if (front == - 1 || front > rear)
{
printf("Queue Underflow \n");
return ;
}
else
{
printf("Element deleted from queue is : %d\n", q[front]);
front = front + 1;
}
}
void display()
{
int i;
if (front == - 1)
printf("Queue is empty \n");
else
{
printf("Queue is : \n");
for (i = front; i <= rear; i++)
printf("%d ", q[i]);
printf("\n");
}
}
void main()
{
int choice;
printf("1.Insert element to queue \n");
printf("2.Delete element from queue \n");
printf("3.Display all elements of queue \n");
printf("4.Quit \n");
do
{
printf("Enter your choice : ");
scanf("%d", &choice);
switch (choice)
{
case 1:
insert();
break;
case 2:
delete();
break;
case 3:
display();
break;
case 4:
printf("EXIT");
}
}while(choice!=4);
}
/* ""OUTPUT""
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice : 1
Inset the element in queue : 10
Enter your choice : 1
Inset the element in queue : 20
Enter your choice : 1
Inset the element in queue : 30
Enter your choice : 3
Queue is :
10 20 30
Enter your choice : 2
Element deleted from queue is : 10
Enter your choice : 2
Element deleted from queue is : 20
Enter your choice : 3
Queue is :
30
Enter your choice : 4
EXIT
*/
#include <stdio.h>

#define MAX 50
int q[MAX];
int rear = - 1;
int front = - 1;
void insert()
{
int add_item;
if (rear == MAX - 1)
printf("Queue Overflow \n");
else
{
if (front == - 1)
front = 0;
printf("Inset the element in queue : ");
scanf("%d", &add_item);
rear = rear + 1;
q[rear] = add_item;
}
}

void delete()
{
if (front == - 1 || front > rear)
{
printf("Queue Underflow \n");
return ;
}
else
{
printf("Element deleted from queue is : %d\n", q[front]);
front = front + 1;
}
}
void display()
{
int i;
if (front == - 1)
printf("Queue is empty \n");
else
{
printf("Queue is : \n");
for (i = front; i <= rear; i++)
printf("%d ", q[i]);
printf("\n");
}
}
void main()
{
int choice;
printf("1.Insert element to queue \n");
printf("2.Delete element from queue \n");
printf("3.Display all elements of queue \n");
printf("4.Quit \n");
do
{
printf("Enter your choice : ");
scanf("%d", &choice);
switch (choice)
{
case 1:
insert();
break;
case 2:
delete();
break;
case 3:
display();
break;
case 4:
printf("EXIT");
}
}while(choice!=4);
}
/* ""OUTPUT""
1.Insert element to queue
2.Delete element from queue
3.Display all elements of queue
4.Quit
Enter your choice : 1
Inset the element in queue : 10
Enter your choice : 1
Inset the element in queue : 20
Enter your choice : 1
Inset the element in queue : 30
Enter your choice : 3
Queue is :
10 20 30
Enter your choice : 2
Element deleted from queue is : 10
Enter your choice : 2
Element deleted from queue is : 20
Enter your choice : 3
Queue is :
30
Enter your choice : 4
EXIT
*/
Loading

0 comments on commit 63c2406

Please sign in to comment.