Sort array

have a program to sort arrary and print sorted elements after each number is entered.

have the sort working, but can't get it to print sorted arrary after each element.
this is waht i have so far

for (i = 0; i < size; ++i)
{
printf("cell %d ", i);
scanf("%d", &sorty[i]);


for (i = 0; i <= sorty[i]; ++i)
{
insertion_sort (sorty, size);// calling sort program
printf("cell %d %d
", i, sorty[i]);
}
}

Comments

  • [b][red]This message was edited by stober at 2005-2-28 10:3:5[/red][/b][hr]
    is this what you are looking for?

    [code]
    int i,j;
    : for (i = 0; i < size; ++i)
    : {
    : printf("cell %d ", i);
    : scanf("%d", &sorty[i]);
    :
    : insertion_sort (sorty, i+1);// calling sort program
    for(j = 0; j < i; j++)
    : printf("cell %d %d
    ", j, sorty[j]);
    : }
    :
    [/code]


  • : [b][red]This message was edited by stober at 2005-2-28 10:3:5[/red][/b][hr]
    : is this what you are looking for?
    :
    : [code]
    : int i,j;
    : : for (i = 0; i < size; ++i)
    : : {
    : : printf("cell %d ", i);
    : : scanf("%d", &sorty[i]);
    : :
    : : insertion_sort (sorty, i+1);// calling sort program
    : for(j = 0; j < i; j++)
    : : printf("cell %d %d
    ", j, sorty[j]);
    : : }
    : :
    : [/code]
    :
    :
    : in sort j the first 2 cells are all zeros. this is what i want : nums to sort 5, 1, 3
    user enter 5
    sort 5
    show 5
    user enter 1
    sort 1 5
    show 1 5
    user enter3
    sort 1, 3, 5
    show 1, 3, 5
    thanks

  • : : [code]
    : : int i,j;
    : : : for (i = 0; i < size; ++i)
    : : : {
    : : : printf("cell %d ", i);
    : : : scanf("%d", &sorty[i]);
    : : :
    : : : insertion_sort (sorty, i+1);// calling sort program
    : : for(j = 0; j <[red]=[/red] i; j++)
    : : : printf("cell %d %d
    ", j, sorty[j]);
    : : : }
    : : :
    : : [/code]

    If the change shown in [red]RED[/red] above doesn't do it, then check the insertion_sort() function for errors.
  • : : : [code]
    : : : int i,j;
    : : : : for (i = 0; i < size; ++i)
    : : : : {
    : : : : printf("cell %d ", i);
    : : : : scanf("%d", &sorty[i]);
    : : : :
    : : : : insertion_sort (sorty, i+1);// calling sort program
    : : : for(j = 0; j <[red]=[/red] i; j++)
    : : : : printf("cell %d %d
    ", j, sorty[j]);
    : : : : }
    : : : :
    : : : [/code]
    :
    : If the change shown in [red]RED[/red] above doesn't do it, then check the insertion_sort() function for errors.

    thanks
    it did work
    :

Sign In or Register to comment.

Howdy, Stranger!

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

Categories