# it is very urgent

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};

or in syntax form.............................it is very urgent

Thanks

• Hello may be there are many more good solution to this problem as u've said its urgent I am trying to help with whatever is in top of my head....

u can make a map as u'r sorted numbers are key and value will be like count of that particular number. like :
1 ---- 3
2 ---- 2
3 ---- 3
.....
7 ---- 1

now iterate the map once from top to bottom add all the left side numbers and decrement one from right side. so it will be like....
1 ---- 2
2 ---- 1
3 ---- 2
.....
7 ---- 0

and array2[15]={1,2,3,4,5,6,7,}

now again do the same....as 7 --- 0 has a count 0 dont add this number in this iteration.... do it again and again until all the right side become 0.

you can use two separate array to implement this but if STL is accepted then I think u can try std::map. but if u dont know template, just use arrays.

Hope this will help....if not then forgive me....
-------------->ASH

: 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};
:
: or in syntax form.............................it is very urgent
:
: Thanks
:
:

• Respected ASH 1984!

i am very thankful to you....for the solution of my problem...
and i achive my goal only one attemp............thanks
program as

#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();
}
******* IF U CAN MORE SHORT THIS PROGRAM PLEASE REPLY ME *******
• It's quite short, I dont think I can make it shorter. u did gr8.
-------------->ASH
:
: Respected ASH 1984!
:
: i am very thankful to you....for the solution of my problem...
: and i achive my goal only one attemp............thanks
: program as
:
: #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();
: }
: ******* IF U CAN MORE SHORT THIS PROGRAM PLEASE REPLY ME *******
:

• :
: Respected ASH 1984!
:
: i am very thankful to you....for the solution of my problem...
: and i achive my goal only one attemp............thanks
: program as
:
: #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();
: }
: ******* IF U CAN MORE SHORT THIS PROGRAM PLEASE REPLY ME *******
:
[/b]

Here is a more effective version without the nested loops:

[code]
#include <stdio.h>

int main()
{
int array[15]={1,1,1,2,2,3,3,3,4,4,5,5,5,6,7};
int sort[8]={0};
int i, j;
int array_n=0;

for(i=0; i<15; i++)
{
sort[ array[i] ]++;
if(array_n < sort[ array[i] ])
array_n = sort[ array[i] ];
}

for(i=0; i<array_n; i++)
{
for(j=0; j<8; j++)
{
if(sort[j] > 0)
{
printf("%d ", j);
sort[j]--;
}
}
printf("
");
}

return 0;
}
[/code]
• HI Mr Landin,
are like to inform me that what logic behind in your program??
i think my program is not bad ..it working quit well and secondly
i want to saved outputs in another array but your program can't
and third thing is taht i have used struct by this i can move the
other data wich attech to the no.s(1,1,1,2,2,3...).and i used
this program or technique in the "round robin cpu scheduling" if
you know.....in round robin we divde the processes in to a quantam no. but processes no is no divide let suppose
(p1,p2,p3,p4)
after divide {p1,p2,p3,p4,p1,p3,p1}
can you help me in "sjf" technique both preemted and non preemted?
please give me some logics of sjf..... not send program (if u dont like)
• : HI Mr Landin,
: are like to inform me that what logic behind in your program??

[blue]It uses indecies 0-7 and counts how many times one of the numbers is found.

It uses array_n to count the number of arrays you can form from the original array. I just print them, but it would of course be possible to copy the data to arrays instead.
[/blue]

: i think my program is not bad ..it working quit well

[blue]If you clock your program and compare it to a program without nested loops, you will see that it is very slow in comparation.
Also, you write several instructions on one line and use no indention, making it very hard to read the code.[/blue]

: i want to saved outputs in another array but your program can't

[blue]Simply replace the printf() with memcpy() to another array.[/blue]

: and third thing is taht i have used struct

[blue]Simply replace the data type with struct, I doesn't change the algorithm itself.[/blue]

by this i can move the
: other data wich attech to the no.s(1,1,1,2,2,3...).and i used
: this program or technique in the "round robin cpu scheduling" if
: you know.....in round robin we divde the processes in to a quantam no. but processes no is no divide let suppose
: (p1,p2,p3,p4)
: after divide {p1,p2,p3,p4,p1,p3,p1}
: can you help me in "sjf" technique both preemted and non preemted?
: please give me some logics of sjf..... not send program (if u dont like)
:

[blue]Yes I know about round robin, but I don't understand what you want to do, or how this program is related to OS scheduling.[/blue]