Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

diffrent sorting

im tooim too Posts: 42Member
Hello!

let suppose a sorted array has some numbers like this
array1[15]={1,1,1,2,2,3,3,3,4,4,5,5,5,6,7};
i want these numbers save in an other array like this
array2[15]={1,2,3,4,5,6,7,
1,2,3,4,5,
1,3,5};
OR
array2[15]={1,2,3,4,5,6,7,1,2,3,4,5,1,3,5};

please please....solve my problem.........by giving some logics
or in syntax form.............................it is very argent

Thanks

Comments

  • abhijitsatheabhijitsathe Posts: 2Member
    Hi,
    Its a very simple program.

    STEP1: declare one array int freq[10] and initialize all of its locations with 0
    STEP2: count frequency of each digit from sorted array and copy into freq[] array.
    for e.g. 1 appears 3 times, hence freq[1] = 3, 2 appears 2 times hence frq[2]=2 etc.
    STEP3:Now scan each location of array freq[], copy index value say I into final array if and only if frq[i] > 0.
    Reduce frq[i] by 1.
    Repeat this STEP3 till all the locations of array are initialized to 0.

    REMEMBER ARRAY freq[] STORES THE FREQUENCY OF EACH NUMBER. HERE MY ASSUMPTION IS ALL NUMBERS WITHIN SORTED ARRAY SINGLE DIGIT.

    BYE.
    BEST OF LUCK



  • im tooim too Posts: 42Member


    Respected Abhijit Bahi!
    i am realy thankful to you that you help me..........
    i have been very upset since last week due to this problem
    but now... by your help ...i solve problem............
    according to your logic.........

    #include
    #include
    void main(void)
    {
    clrscr();
    int array[15]={1,1,1,1,2,2,3,3,3,4,4,5,6,6,7};
    struct sort {int freq,num;}sort[7];
    int a,b=0,c,d=0;
    for(a=1;a<=7;a++)
    {
    for(c=0;c<15;c++)
    if(array[c]==a){b++;}sort[d].freq=b;sort[d].num=a;b=0;d++;
    }b=0;
    for(c=0;c<15;c++){
    for(a=0;a<d;a++)
    if(sort[a].freq>0){array4[b]=sort[a].num;sort[a].freq=sort[a].freq-1;b++;}}
    for( a=0;a<15;a++)
    printf("
    %d ",array[a]);
    getch();
    }
    please................help me.....continously
  • abhijitsatheabhijitsathe Posts: 2Member
    Hi,
    I think you made it little complicated. You don't need to use struct for this. Array indices from 1 to 7 could be used to store frequency count.

    example:

    1,1,1,2,2,3,3,3,4,4,5,5,5

    this could be stored in array freq[] like:
    freq[1] = 3
    freq[2] = 2
    freq[3] = 3
    freq[4] = 2
    freq[5] = 3

    Bye.



Sign In or Register to comment.