Commit 5933b136 by shtaya

qsort implemented

parent 242afdaa
Showing with 11 additions and 23 deletions
......@@ -27,13 +27,12 @@ typedef struct sales
void readFile(sales_t *);
void dispData(sales_t *);
void sortData(sales_t *);
int cmp(const void *p, const void *q);
int main(void)
{
int i;
sales_t *data;
sales_t **pArray;
data = (sales_t*)malloc(sizeof(sales_t)*NFIELD);
if (data == NULL)
......@@ -42,27 +41,22 @@ int main(void)
exit(EXIT_FAILURE);
}
pArray = (sales_t**)malloc(sizeof(sales_t*)*NFIELD);
if (pArray == NULL)
{
printf( "memory allocation error\n" );
exit(EXIT_FAILURE);
}
for(i = 0; i < NFIELD; i++)
{
pArray[i] = &data[i];
}
readFile(data);
readFile(*pArray);
//dispData(data);
dispData(*pArray);
qsort(data, NFIELD, sizeof(sales_t), cmp);
sortData(*pArray);
//dispData(data);
return 0;
}
int cmp(const void *p, const void *q)
{
return ((sales_t*)p)->book_id - ((sales_t*)q)->book_id;
}
void readFile(sales_t *sp)
{
FILE *fp;
......@@ -91,16 +85,10 @@ void readFile(sales_t *sp)
void dispData(sales_t *sp)
{
int i;
for(i = 0; i < 100; i++)
for(i = 0; i < 500; i++)
{
printf("%d,%d\n", (sp+i)->person_id,(sp+i)->book_id);
}
return;
}
void sortData(sales_t *sp)
{
return;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment