Hub Of Geekz

  • Home
  • About Me
  • Contact Us
  • Home
  • Languages
    • C++
    • Java
    • Perl
    • Prolog
    • Bootstrap
  • Database
    • SQL
    • PL/SQL
  • Study
    • Java
      • Java Collection
      • Java Concurrency
      • Java Interview Questions
      • Java Networking
    • Number System
  • Kavita
  • Entertainment
    • Hinglish Cafe
    • Videos
    • Jokes
  • Windows Tricks
  • How To

Thursday, 15 August 2013

Insertion Sort using C++

 Earthcare Foundation NGO     17:03     C Plus Plus     No comments   



Program Code:

#include<iostream.h>
#include<conio.h>
main()
{
int a[50],size;
char ch;
cout<<"Enter size of array\n";
cin>>size;
cout<<"Enter the order of sorting\n";
cout<<"Enter a for ascending or d for decending\n";
cin>>ch;
cout<<"Enter elements of array\n";
for(int i=0;i<size;i++)
{
cin>>a[i];
}
int t;
for(int i=1;i<=size;i++)
{
t=a[i];
for(int j=0;j<i;j++)
{
if(t<a[j])
{
for(int k=i;k>=j;k--)
{
a[k]=a[k-1];
}
a[j]=t;
break;

}
}
}
cout<<"The sorted array is\n";
if(ch=='a')
{
        for(int i=0;i<size;i++)
        {
cout<<a[i]<<"\t";
}
}
else if(ch=='d')
{
        for(int i=size-1;i>=0;i--)
{
cout<<a[i]<<"\t";
}
}
getch();
}

Output:


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Bubble sort using C++

 Earthcare Foundation NGO     16:52     C Plus Plus     No comments   



Program Code:


#include<iostream.h>
#include<conio.h>
main()
{
int a[50],size;
char ch;
cout<<"Enter size of array\n";
cin>>size;
cout<<"Enter the order of sorting\n";
cout<<"Enter a for ascending or d for decending\n";
cin>>ch;
cout<<"Enter elements of array\n";
for(int i=0;i<size;i++)
{
cin>>a[i];
}
for(int i=0;i<size;i++)
{
for(int j=0;j<size-i;j++)
{
if(a[j+1]<a[j])
{
int temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
cout<<"The sorted array is\n";
if(ch=='a')
{
        for(int i=0;i<size;i++)
        {
cout<<a[i]<<"\t";
}
}
else if(ch=='d')
{
        for(int i=size-1;i>=0;i--)
{
cout<<a[i]<<"\t";
}
}
getch();
}

Output:


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Selection sort using C++

 Earthcare Foundation NGO     16:42     C Plus Plus     No comments   


Program Code:

#include<iostream.h>
#include<conio.h>
main()
{
int a[50],size;
char ch;
cout<<"Enter size of array\n";
cin>>size;
cout<<"Enter the order of sorting\n";
cout<<"Enter a for ascending or d for decending\n";
cin>>ch;
cout<<"Enter elements of array\n";
for(int i=0;i<size;i++)
{
cin>>a[i];
}
for(int i=0;i<size-1;i++)
{
for(int j=i+1;j<size;j++)
{
if(a[i]<a[j])
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
cout<<"The sorted array is\n";
if(ch=='d')
{
        for(int i=0;i<size;i++)
        {
cout<<a[i];
}
}
else if(ch=='a')
{
        for(int i=size-1;i>=0;i--)
{
cout<<a[i]<<"\t";
}
}
getch();
}


Output:

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Sunday, 11 August 2013

Binary Search using C++

 Earthcare Foundation NGO     22:23     C Plus Plus     No comments   



Program Code:

#include<iostream.h>
#include<conio.h>
int binarySearch(int a[],int,int);

main()
{
int arr[50],size,index,target;
cout<<"Enter the size of array(max 50):\n";
cin>>size;
cout<<"Enter the elements of the array:\n";
for(int i=0;i<size;i++)
{
cin>>arr[i];
}
cout<<"Enter the element to be searched:\n";
cin>>target;
index=binarySearch(arr,size,target);
if(index==-1)
{
cout<<"Element is not present in the list\n";
}
else
{
cout<<"Element is present at index "<<index+1;
}

getch();
}
int binarySearch(int a[],int s,int t)
{
int beg,last,mid;
beg=0;
last=s-1;
while(beg<=last)
{
mid=(beg+last)/2;
if(a[mid]==t)
{
return mid;
}
else if(t>a[mid])
{
beg=mid+1;
}
else
{
last=mid-1;
}
}
return -1;
}

Output:


Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg

Linear Search using C++

 Earthcare Foundation NGO     22:14     C Plus Plus     No comments   



Program Code:


#include<iostream.h>
#include<conio.h>
int linearSearch(int a[],int,int);

main()
{
int arr[50],size,index,target;
cout<<"Enter the size of array(max 50):\n";
cin>>size;
cout<<"Enter the elements of the array:\n";
for(int i=0;i<size;i++)
{
cin>>arr[i];
}
cout<<"Enter the element to be searched:\n";
cin>>target;
index=linearSearch(arr,size,target);
if(index==-1)
{
cout<<"Element is not present in the list\n";
}
else
{
cout<<"Element is present at index "<<index+1;
}

getch();
}
int linearSearch(int a[],int s,int t)
{
for(int i=0;i<s;i++)
{
if(a[i]==t)
{
return i;
}
}
return -1;
}


Output:

Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Google+
  •  Stumble
  •  Digg
Newer Posts Older Posts Home

Ad


Jobsmag.inIndian Education BlogThingsGuide

Subscribe

Do you want fresh and hot updates about us? Then subscribe to our Feeds.

Total Pageviews

Popular Posts

  • Write a program in PL/SQL to print the factorial of a number.
    In this post I will explain how to get the factorial of any given number. For that first you need to know what is the procedure to find ...
  • To find the GCD of two numbers in PROLOG.
    gcd(X,Y):-X=Y,write('GCD of two numbers is '),write(X); X=0,write('GCD of two numbers is '),write(Y); Y=0,write('G...
  • Write a PL/SQL code to get the Fibonacci Sequence
    First, I will explain what is Fibonacci Sequence and how to get this series. So, Fibonacci Sequence is a series of numbers 0,1,1,2,3,5,8,1...

Label

All Articles Best Resources Blogging Boost Traffic Bootstrap C Plus Plus Collection Comedy Comedy Posts Comedy Videos Concurrency creative commons website Education Employee Entertainment Fibonacci Sequence free images GirlFriend Hinglish Cafe How To Image Websites Inspirational Java Java Interview Questions Java Networking Kavita Sangrah Life Lock Sreen Love Number System Patterns Perl Picture PL/SQL Plastic Engineering Programming Prolog public domain SEO Servlet Short Story Shortcut Keys Social Media Social Services SQL SuVichar Thread Traffic True Events Ultimate Guide Windows Tricks Windows8.1 WordPress

Blog Archive

  • ►  2020 (43)
    • ►  September (41)
    • ►  August (2)
  • ►  2019 (1)
    • ►  July (1)
  • ►  2018 (9)
    • ►  September (7)
    • ►  July (1)
    • ►  May (1)
  • ►  2017 (8)
    • ►  June (3)
    • ►  May (3)
    • ►  March (1)
    • ►  January (1)
  • ►  2016 (2)
    • ►  September (1)
    • ►  January (1)
  • ►  2015 (91)
    • ►  December (1)
    • ►  November (1)
    • ►  October (6)
    • ►  May (10)
    • ►  March (20)
    • ►  February (50)
    • ►  January (3)
  • ►  2014 (339)
    • ►  December (1)
    • ►  October (55)
    • ►  September (58)
    • ►  August (94)
    • ►  July (64)
    • ►  June (67)
  • ▼  2013 (34)
    • ▼  August (5)
      • Insertion Sort using C++
      • Bubble sort using C++
      • Selection sort using C++
      • Binary Search using C++
      • Linear Search using C++
    • ►  April (29)
  • ►  2012 (20)
    • ►  November (1)
    • ►  October (15)
    • ►  September (4)

Author

  • Earthcare Foundation NGO
  • Kavita house
  • Unknown
  • Unknown

Info

Copyright © Hub Of Geekz | Powered by Blogger
Design by Hardeep Asrani | Blogger Theme by NewBloggerThemes.com | Distributed By Gooyaabi Templates