sign up I login
 advanced
refer a friend - earn nickels!!

Ask & Discuss Questions with Community & Experts

Moderation Team
Ask iit jee aieee pet cbse icse state board community Discussion Response Post to: C++......
Forum Index -> Games, Puzzles and Quizzes -> View Full Question like the article? email it to a friend.  
Author Message
antonyajay21 (509)

Blazing goIITian

Olaaa!! Perrrfect answer. 93  [115 rates]

antonyajay21's Avatar

total posts: 334    
offline Offline
#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>
#include <values.h>
#include <time.h>
#include <string.h>

const int max=1000;
int list[max];
FILE *fp;

void insertion(int aa[],int max1)
{
    int a,b,v;

    for(a=1;a<max1;a++)
    {
       v = aa[a];
       b = a;
       while(aa[b-1] > v)
       {
       aa[b] = aa[b-1];
       b = b - 1;
       }
       aa[b] = v;
    }
}

void quicksort(int min1,int max2)
{
int t;

if (max2 > min1)
{
   int v = list[max2];
   int i = min1 - 1;
   int j = max2;
   do
   {
      do
      {
     i = i + 1;
      } while (list[i] < v);
      do
      {
     j = j - 1;
      } while (list[j] > v);
      int t = list[i];
      list[i] = list[j];
      list[j] = t;
   } while (j > i);
   list[j] = list[i];
   list[i] = list[max2];
   list[max2] = t;
   quicksort(min1,i-1);
   quicksort(i+1,max2);
 }
}

void main()
{

int i,j,k,l;
char any1[8],any2[8];

cout << "Enter a file name ";
cin >> any1;
/*if(strlen(any1) > 12)
   cout << "File name input error."; */


fp = fopen(any1,"wb");
    for(j=0;j<30000;j++)
    {
    k = rand();
    fprintf(fp,"%d ",k);
    }
fclose(fp);
fp = fopen(any1,"rb");
    i = 0;
    while (fscanf(fp,"%d ",l) != 0)
    {
      list[i] = l;
      i = i + 1;
    }
fclose(fp);

/*int min = 0;
quicksort(min,max); */
insertion(list,max);

cout << "Enter an output file : ";
cin >> any2;
fp = fopen(any2,"wb");
  for(i=0;i<max;i++)
  {
      int r = list[i];
      fwrite(&r,sizeof(int),1,fp);
  }
fclose(fp);
}




Be not afraid of growing slowly.
Be afraid only of standing still.

 this reply: 10 points  (with Olaaa!! Perrrfect answer.   in 2 votes )   [?]
 
You have to be logged on to rate
  
 

Top Offers for goIITians
Correspondence Courses
Brilliant Tutorials
Narayana Institute
Aakash Institute
Classroom/Crash Courses
Narayana - Kota , Delhi , Others
Brilliant Tutorials - Class , Crash
Aakash Institute - Medical , Engg
Online Test Series
Brilliant Tutorials
Narayana Institute
Aakash Institute
Mahesh Tutorials
AMITY      Sri Chaitanya