Dynamic arrays + shell sorting method

Hello everybody.
Basically, what I want to know is, how would shell shorting method work in such program , cause I don't clearly understand the algorithm of this method..

The program:
#pragma argsused
#include
#include
#include
#include

int i,j; //cikla mainigie
int *p; //norade uz masivu ar noradem
int n; //masiva elementu daudzuma mainigais
int temp; //temp mainigais, hvz?
int *garumi; //dinamiska masivo kolonnu,rindu skaita daudzuma masivs
int **matrica; //dinamiskais masivs

int main(){
n=-10;

while (n<0)
{
printf("How much rows??
");
scanf("
%d", &n);
if (n<0)
{
printf("The amount of rows must be > 0!");
getch();
clrscr();
}
}
garumi=(int*)calloc(n,sizeof(int));
matrica=(int**)calloc(n,sizeof(int*));
for (i=0;i 0!");
getch();
clrscr();
}
printf ("How much rows in %d. row??
", i+1);
scanf ("%d",&garumi[i]);

}
for (j=0;j<garumi[i];j++)
{
printf("Enter [%d][%d] element: ", i+1,j+1);
scanf("%d",&garumi[i]);

}

}
getch();

}
and now I should sort it, but I don't know how to do it, if anyone can help me, thanks :)

I would also like to know how can I change the amount of columns in a row? like add/delete function? I'm so confused about all this.

Comments

  • I don't know what you are doing here:

    garumi=(int*)calloc(n,sizeof(int));
    matrica=(int**)calloc(n,sizeof(int*));

    but you are not allocating a 2D array. See this link:

    http://c-faq.com/aryptr/dynmuldimary.html
  • it actually does allocate a 2d array

    garumi is a 1d array of column and row count in the second array and matrica is the array itself... that's the basic idea of it, it all works so far, but i need to sort the array I have now, and change the column count in each row :)

    int *garumi; //dinamiska masivo kolonnu,rindu skaita daudzuma masivs - comment states, array which consists of number of rows and columns in the dynamic array




    int **matrica; //dinamiskais masivs - the comment states, the dynamic array
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

In this Discussion