Wednesday, October 30, 2013

c program to implement quicksort


c program to implement quicksort

1. Quicksort is a divide and conquer algorithm.
2. Quicksort first divides a large list into two smaller sub-lists: the low elements and the high elements. Quicksort can then recursively sort the sub-lists.
The steps are:
  1. Pick an element, called a pivot, from the list.
  2. Reorder the list so that all elements with values less than the pivot come before the pivot, while all elements with values greater than the pivot come after it (equal values can go either way). After this partitioning, the pivot is in its final position. This is called the partition operation.
  3. Recursively apply the above steps to the sub-list of elements with smaller values and separately the sub-list of elements with greater values.

3.  on average,it makes O(n log n) comparisons to sort n items.


#include<stdio.h>
#include<conio.h>

int partition( int * , int , int  );
void quicksort( int *, int low, int high );
void display(int *, int);

void swap (int *a, int left, int right)
{
 int temp;
 temp=a[left];
 a[left]=a[right];
 a[right]=temp; 
}//end swap
void quicksort( int *a, int low, int high )
{
 int pivot;
 // Termination condition! 
 if ( high > low )
 {
  pivot = partition( a, low, high );
  quicksort( a, low, pivot-1 );
  quicksort( a, pivot+1, high );
 }
} //end quicksort
int partition( int *a, int low, int high )
{
 int left, right;
 int pivot_item;
 int pivot = left = low; 
 pivot_item = a[low]; 
 right = high;
 while ( left < right ) 
 {
  // Move left while item < pivot 
  while( a[left] <= pivot_item ) 
   left++;
  // Move right while item > pivot 
  while( a[right] > pivot_item ) 
   right--;
  if ( left < right ) 
   swap(a,left,right);
 }
 // right is final position for the pivot 
 a[low] = a[right];
 a[right] = pivot_item;
 return right;
}//end partition


int main()
{
 int a[50], i, n;
 printf("\nEnter no. of elements: "); 
 scanf("%d", &n);
 printf("\nEnter the elements: \n");
 for (i=0; i<n; i++)
  scanf ("%d", &a[i]);
 printf("\nUnsorted elements: \n");
 display(a,n);
 quicksort(a,0,n-1);
 printf("\nSorted elements: \n");
 display(a,n);
 getch();
 return 0;
}//end main
void display(int *a, int n)
{
 int i;
 for (i=0; i<n; i++)
  printf(" %d ", a[i]);
 printf("\n");
}//end display


Below is the output of the above program.





Friday, October 25, 2013

incremental backup RMAN with multiple channels



below is the command in oracle to take rman incremental backup.
RMAN> run
{
   allocate channel c1  device type disk format 'I:\RMAN_BACKUP\rman_bkp_%U';
   allocate channel c2  device type disk format 'I:\RMAN_BACKUP\rman_bkp_%U';
   allocate channel c3  device type disk format 'I:\RMAN_BACKUP\rman_bkp_%U';
   backup incremental from scn 5768934213 database;
}

where 'rman_bkp_%U' is format of backup piece whose name will start with 'rman_bkp'.
above command used to allocate multiple channels to take incremental backup.


If you want to take incremental backup with single channel then below is the command which is executed using rman utitlity.

RMAN > backup device type disk incremental from scn 5768934213 database format 'I:\RMAN_BACKUP\rman_bkp_%U';

scn specifies from where to start backup.

Thursday, October 24, 2013

tracing ip address to capture successful / unsuccessful login attempts oracle by enable auditing


In this tutorial, I will explain how to capture ip address of the users trying to connect to database.
We can do this task using enabling the auditing in database. By enabling the auditing, we can trace ip
address of all the users having successful or unsuccessful login attempt. Below is the step by step procedure to enable auditing in oracle database.


Step 1: login to database
set the value of audit_trail parameter to DB.



Step2: bounce the database to make the above changes effective in database.























Step 3: audit the create session by executing below commands.



Step 4: now auditing has been enabled.
Now its time to see all  successful/unsuccessful login attempts made by users.
See the view sys.aud$ table which shows all the details of users made attempt to connect to database.
Select * from sys.aud$;
In this view , returncode column specifies the successful/unsuccessful login .
if any row contains value 1017 for column returncode then the user in that row has specified
incorrect username/password , in other word user has attempted unsuccessful login attempt.






























Friday, October 4, 2013

Programming Example of creating class in C#






C# Program to creating class 
In this csharp tutorial guideline while creating class
1. The class name should be noun and meaningful.
2. Use either pascal case or camel case. In camel case, the first letter is small. Ex. camelCase. In pascal case first letter is capital. Ex. PascalCase. It is strictly recommended you to use pascal case for class name and camel case for variable name.
3. Your class name should not contain any special character except underscore (_) or digit. Must start your class name with character.
4. Don’t use reserved keyword for class name.
Then we show the result in output
For this we use console readline and console write line



Program :

using System;


namespace Creating_Class

{
    class accept //Creating 1st. class
    {
        public string name;
        public void acceptdetails()
        {
            Console.Write("Enter your name:\t");
            name = Console.ReadLine();
        }
    }

    class print // Creating 2nd class

    {
        public void printdetails()
        {
            //Creating object of 1st. class
            accept a = new accept();
            //executing method of 1st class.
            a.acceptdetails();
            //Printing value of name variable
            Console.WriteLine("Your name is " + a.name);
        }
    }
    class Program //Creating 3rd class
    {
        static void Main(string[] args)
        {
            print p = new print();
            p.printdetails();
            Console.ReadLine();
        }
    }
}






  


output :













Saturday, September 28, 2013

C# Program to add Two numbers Csharp


C# Program to add two numbers Integers 
In this csharp tutorial we add two numbers
First we take two numbers and store them in variables
Then we show the result in output
For this we use console readline and console write line

Program :
using System;
 
namespace CsharpPrograms
{
    class Program
    {
        static void Main(string[] args)
        {
 
            int x;
            int y;
            int result;
            Console.Write("\n Enter the first number to be added: ");
            x=Convert.ToInt32(Console.ReadLine());
            Console.Write("\n Enter the second number to be added: ");
            y = Convert.ToInt32(Console.ReadLine());
            result = x + y;
            Console.Write("\n The sum of two numbers is: "+result);
            Console.ReadLine();
        }
    }
}
Output:

Sunday, September 22, 2013

Delete files older than three days linux


In this Tutorial  i wiill  explain how  to  delete files or sdr  files in linux 

find / -name '*.sdr' -mtime +3 -exec rm {} \;
where '/' is mount point,
*.sdr is all .sdr type files which are to be deleted and +3 indicates files older than 3 days.


 

© 2013 1000TechTips. All rights resevered. Designed by Templateism

Back To Top