Term of service
Disclaimer
Privacy Policy
Contact Us
About Us
Zama Codes
Home
C++
Data Structure
JAVA
Sorting
Monday 26 November 2018
Selection sorting Dynamically
November 26, 2018
C++
,
Computer programming
,
Data structure
,
sorting
No comments
Worst-Complexity: n ^ 2
Average-Complexity: n ^ 2
Best-Complexity: n ^ 2
Space-Complexity: 1
#include<iostream>
using namespace std;
/*********************sorting function********************/
void selection_Sort(int arr[], int n)
{
int i, j, min;
for (i = 0; i < n-1; i++)
{
min = i;
for (j = i+1; j < n; j++)
if (arr[j] < arr[min])
min = j;
swap(arr[min],arr[i]);
}
}
/****************** Printing values*****************************/
void print_Array(int arr[], int size)
{
int i;
for (i=0; i < size; i++)
cout<<arr[i];
cout<<endl;
}
/**********************Driver function*************************/
int main()
{
int *arr;
int n;
cout<<"How many numbers your want to sort:"<<endl;
cin>>n;
arr=new int[n];
cout<<"Enter the numbers:"<<endl;
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
selection_Sort(arr, n);
cout<<"After sorting array: \n"<<endl;
print_Array(arr, n);
return 0;
}
Email This
BlogThis!
Share to Twitter
Share to Facebook
Newer Post
Older Post
Home
0 comments:
Post a Comment
Popular
Tags
Blog Archives
Insertion sorting using pointers and function
Write a program for insertion sorting. #include <iostream> using namespace std; void insertionSort(int *p,int siz...
Predefined Array-Copy method in JAVA
public class ArrayCopy { public static void main(String []args) { int arr[]=new int[]{1,2,3,4,5,6,7,8,9,10}; for(int i:arr) { ...
Selection sorting Dynamically
Worst-Complexity: n ^ 2 Average-Complexity: n ^ 2 Best-Complexity: n ^ 2 Space-Complexity: 1 #include<iostream&...
Circular queue using array(insertion, deletion)
#include <iostream> using namespace std; int Q[10]; int size=10; int count=0; int rear=0; int front=0; void enQ(in...
Implementation of queue using linklist (C++)
#include<iostream> using namespace std; struct queue { int data; struct queue *next; }; queue *front=NULL; queu...
User Define Class array Simple Java program
import java.util.Scanner; public class ZamaCodes { public static void main(String[] args) { Employee E=new Employee(); Employe...
"Infix to Post-fix" conversion and "parenthesis check using "User define" stacks C++
#include<iostream> using namespace std; char stack[100]; // char postfix[100]; char exp[100]; // mathematical expression ...
For Each Loop in Java: A Beginner's Guide
The "for each loop in Java" is a powerful tool for iterating through arrays and collections. In this guide, we will learn how to ...
Contact Form
Name
Email
*
Message
*
Labels
BS(CS) notes
C++
Computer programming
Data structure
JAVA
sorting
Tips
Blog Archive
►
2023
(1)
►
July
(1)
►
2019
(12)
►
March
(8)
►
February
(4)
▼
2018
(15)
►
December
(4)
▼
November
(5)
Singly Linklist in C++ (insertion at satart,middle...
Binary Search in C++
Selection sorting Dynamically
"Infix to Post-fix" conversion and "parenthesis ch...
A Program which uses linear searching? C++
►
October
(5)
►
June
(1)
►
2017
(3)
►
September
(3)
0 comments:
Post a Comment