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 X
Share to Facebook
Newer Post
Older Post
Home
0 comments:
Post a Comment
Popular
Tags
Blog Archives
"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 ...
LinkedList implementation in JAVA
import java.util.Scanner; class Node { int data; Node next; } //**********************LinkedList Class******************...
Insertion sorting using pointers and function
Write a program for insertion sorting. #include <iostream> using namespace std; void insertionSort(int *p,int siz...
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 ...
Tree traversal (preorder,inorder,postorder) using linklist (c++)
#include<iostream> using namespace std; struct node { int data; struct node *left; struct node *right; }; /*...
Selection sorting Dynamically
Worst-Complexity: n ^ 2 Average-Complexity: n ^ 2 Best-Complexity: n ^ 2 Space-Complexity: 1 #include<iostream...
Declaration of one dimensional array of numbers and characters in JAVA
-Declare and initialize two one dimensional arrays with 1) Numbers 2) Characters 1.1-Print the content of both arrays 1.2-Get the l...
Computer fundamental | Pradeep K. Sinha and Priti Sinha | Notes for BS(cs)
This is the notes of computer fundamentals which is written by "Pradeep K. Sinha and Priti Sinha". Notes for the followin...
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