This is exactly what I was looking for. You made qsort very easy to understand. Thank you.
@stefanbozic88802 жыл бұрын
This video explains exactly what I was looking for with qsort and how it could be implemented for structures, thanks a bunch.
@rafaelpieri2771 Жыл бұрын
Not all heroes wear capes.
@shaboobis92832 жыл бұрын
Amazing lesson! So much information that is relevant to what I need to do. I'm very glad you provided a struct example. Bravo my friend.
@salvationwithoutregret97812 жыл бұрын
Superb explanation! Simple but strong. Im trying to make it through CS in College and this is a help!
@arpitanand4514 жыл бұрын
Past some days i am studing c language... And believe me no one is like you. Continue it sir.......
@whiteimposter93043 жыл бұрын
dud do you study in school or without?
@nullzero92242 жыл бұрын
Well Explained and very nice tutorial. Thank you so much
@sahilkhan19093 жыл бұрын
I absolutely like this video, this is exactly what I was looking for a couple of days.
@anandraj98592 жыл бұрын
Thanks for the beautiful explanation....... Thank u soooo much..
@md.jannatulnayem43282 жыл бұрын
Good content...absolutely loved it 🔥
@syedmufassiriqbal44734 жыл бұрын
Very help full video , nyc explanation ✊🏻thank u sir .
@ironironowski10634 жыл бұрын
HIT!! NIEWISKI GO N1ENAWIDZ1 ZNALAZŁ JEDEN PR0STY TRICK NA ZDANIE KOLOSA
@MISSONVAI4 жыл бұрын
HIT !! THE SLAWS HIM HIM FOUND ONE SIMPLE TRICK ON THE COLLECT'S OPINION (your comment translation)
@ukaszkiepas574 жыл бұрын
xD
@uditmahajan5554 жыл бұрын
Hi, it would be awesome if you add a section or even a photo of topics you'll cover in a video in your future videos! The video was nice (:
@nathanoosterhuis62323 жыл бұрын
Thank you sir, good explanation
@Clara-cj2tu3 жыл бұрын
Thank you so much!! This video is really helpful
@nml45463 жыл бұрын
Very nice, thanks, I was thinking I had to write my own sort, and actually, but this is much better.
@nbk3304 жыл бұрын
very easy way of explanation
@harshitgupta4243 жыл бұрын
thank you soo much ! great work there .
@asmakhan5414 жыл бұрын
Great explanation sir thank u😀😀
@siraj15124 жыл бұрын
Very neat. Thank you
@Jack-ux3yh3 жыл бұрын
very good video,learned a lot
@sartrap14 жыл бұрын
thank you!!! really helpful
@Inublue503 жыл бұрын
Well taught!
@TheAbsoluteSir3 жыл бұрын
How are you utilizing *pa and *pb in the compareInt function if you are not passing anything in the arguments from main?
@programmingwithsikander35393 жыл бұрын
kzbin.info/www/bejne/oniQm5mLnrljaNk It's called from inside qsort function. The above link should help you.
@laurelanderson75724 жыл бұрын
Thank you! I understand this now!
@azizprasetyo36762 жыл бұрын
Thank u sir😇
@ViralVideos-uz1mn5 жыл бұрын
very helpful video
@nguyenphucquanganh70313 жыл бұрын
thank you dude
@karamveersachdeva9354 жыл бұрын
really helpful
@rhkhandu3 жыл бұрын
Would you please give the link of the PDF manual you followed during explanation the Syntex of qsort?
@programmingwithsikander35392 жыл бұрын
Its man page. man qsort
@kushbind82075 жыл бұрын
Thank you bro...😇😇😇😇
@tanvbd3 жыл бұрын
Professor, I need to solve an array of pointers using qsort. I don't have enough time and I need to submit these projects within 2 weeks in my school. I honestly need help.
@vishalmitra_4 жыл бұрын
Wooow😊♨️ I want to know reverse shotcut too
@MISSONVAI4 жыл бұрын
sir, 'pa' and 'pb' are void pointers then how can we pass these two pointers to Strcmp() without typecasting them to char pointer?
@programmingwithsikander35394 жыл бұрын
In C, We can assign address of any type to a void pointer without typecasting. Also the address stored in void pointer can be assigned to typed pointer. In C++ and in Turbo C, we require typecasting when we assign void pointer to typed pointer. To make it work, try this strcmp((char *)pa, (char *)pb);
@GenieChef4 жыл бұрын
Dude you are my hero! Thank you!
@qwert93134 жыл бұрын
Thank you so much ❤️
@rathnaganesh5954 жыл бұрын
great !!! Thank you :)
@surjeetsingh-tj7di4 жыл бұрын
Awsome bro
@anmolraj66044 жыл бұрын
Well taught
@tanvbd3 жыл бұрын
Professor I am trying to qsort using name but its not happening. int cmpname(const void * pa, const void * pb ){ const card_t *p1 = pa; const card_t *p2 = pb; // return p1->name - p2->name; return strcmp(p1->name, p2->name); } int n = sizeof(cards) / sizeof(card_t); qsort(cards, n, sizeof(card_t), cmpname);
@programmingwithsikander35393 жыл бұрын
What is type of cards, is it multidimensional array or array of pointers?
@tanvbd3 жыл бұрын
an array of pointers to structs
@axolet4 жыл бұрын
Thank you!
@bashmogd44684 жыл бұрын
thanx very much
@purabmodi66234 жыл бұрын
whats the value at address "pa" and "pb" ?
@Zambo234 жыл бұрын
so clear, ty
@orangeshoes4 жыл бұрын
Thank you ❤️
@skitnado255 жыл бұрын
Tried same thing but I kept getting id in something not a structure or union, mycode: /* QSORT and bsearch that returns a 24-bit color value using * built in library function */ #include #include #include //declare color comparism int ColorCompare(const void *pa, const void *pb); //define struct for holding RGB color data typedef struct _RGB { int id; char color[16]; int value; }RGB_t; int main(){ int i, n; // record hold RGB color data RGB_t records [] = {{0,"black", 0x000000}, {1,"blue", 0x0000AA}, {2,"green", 0x00AA00}, {3,"cyan", 0x00AAAA}, {4,"red", 0xAA0000}, {5,"magenta", 0xAA00AA}, {6,"brown", 0xAA5500}, {7,"light gray", 0xAAAAAA}, {8,"dark gray", 0x555555}, {9,"light blue", 0x5555FF}, {10,"light green", 0x55FF55}, {11,"light cyan", 0x55FFFF}, {12,"light red", 0xFF5555}, {13,"light magenta",0xFF55FF}, {14,"yellow", 0xFFFF55}, {15,"white", 0xFFFFFF}}; n = sizeof(records) / sizeof(RGB_t); printf("List of colors in before sort records are: "); for(i = 0; i < n; i++){ printf(" %d %s %x ", records.id[i], records.color[i], records.value[i]); printf(" "); } qsort(records, n, sizeof(RGB_t),ColorCompare); printf(" List of colors in afer sort records are: "); for(i = 0; i < n; i++){ printf(" %d %s %x ", records.id[i], records.color[i], records.value[i]); printf(" "); } return 0; } int ColorCompare(const void *pa, const void *pb){ const RGB_t *p1 = pa; const RGB_t *p2 = pb; return strcmp(p1->color, p2->color); }
@programmingwithsikander35395 жыл бұрын
Records is an Array Use records[i].id, records[i].color etc., #include #include #include //declare color comparism int ColorCompare(const void *pa, const void *pb); //define struct for holding RGB color data typedef struct _RGB { int id; char color[16]; int value; }RGB_t; int main(){ int i, n; // record hold RGB color data RGB_t records [] = {{0,"black", 0x000000}, {1,"blue", 0x0000AA}, {2,"green", 0x00AA00}, {3,"cyan", 0x00AAAA}, {4,"red", 0xAA0000}, {5,"magenta", 0xAA00AA}, {6,"brown", 0xAA5500}, {7,"light gray", 0xAAAAAA}, {8,"dark gray", 0x555555}, {9,"light blue", 0x5555FF}, {10,"light green", 0x55FF55}, {11,"light cyan", 0x55FFFF}, {12,"light red", 0xFF5555}, {13,"light magenta",0xFF55FF}, {14,"yellow", 0xFFFF55}, {15,"white", 0xFFFFFF}}; n = sizeof(records) / sizeof(RGB_t); printf("List of colors in before sort records are: "); for(i = 0; i < n; i++){ printf(" %d %s %x ", records[i].id, records[i].color, records[i].value); printf(" "); } qsort(records, n, sizeof(RGB_t),ColorCompare); printf(" List of colors in afer sort records are: "); for(i = 0; i < n; i++){ printf(" %d %s %x ", records[i].id, records[i].color, records[i].value); printf(" "); } return 0; } int ColorCompare(const void *pa, const void *pb){ const RGB_t *p1 = pa; const RGB_t *p2 = pb; return strcmp(p1->color, p2->color); }
@skitnado255 жыл бұрын
@@programmingwithsikander3539 Thank you for the clarification it worked now .
@skitnado255 жыл бұрын
so I added a bsearch to return the value os color from user input as shown below: for (; ;) { printf(" Enter key like black or red for 24 bit color value:"); /* Get the key, with size limit. */ fgets(input,MAX_KEY_SIZE,stdin); /* Remove trailing newline, if there. and check for end of prog */ if((strlen(input) == 1)) { printf(" ****** end of program ********* "); exit(0); } else { if ((strlen(input) > 0) && (input[strlen (input) - 1] == ' ')){ input[strlen (input) - 1] = '\0'; printf(" KEY entered is %s. ",input); RGB_t key = {.color = input}; RGB_t const *RGB_ptr = bsearch(&key, records, n, sizeof (RGB_t), ColorCompare); if (RGB_ptr != NULL) { printf("Value for Color %s is %5x ", RGB_ptr->color, RGB_ptr->value); } else { printf(" Color %s not found ", input); } } } } I get warnings: [Warning] initialization makes integer from pointer without a cast [Warning] (near initialization for 'key.color[0]') from the line of code: RGB_t key = {.color = input}; when I entered: RGB_t key = {.color = "red"}; i get no error and it returns value from records.