Qsort in C

  Рет қаралды 31,167

Programming with Sikander

Programming with Sikander

Күн бұрын

Пікірлер: 66
@ironmonkey1990
@ironmonkey1990 8 ай бұрын
Best video I’ve watched for this topic
@andrew_mb
@andrew_mb 4 жыл бұрын
This is exactly what I was looking for. You made qsort very easy to understand. Thank you.
@stefanbozic8880
@stefanbozic8880 2 жыл бұрын
This video explains exactly what I was looking for with qsort and how it could be implemented for structures, thanks a bunch.
@rafaelpieri2771
@rafaelpieri2771 Жыл бұрын
Not all heroes wear capes.
@shaboobis9283
@shaboobis9283 2 жыл бұрын
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.
@salvationwithoutregret9781
@salvationwithoutregret9781 2 жыл бұрын
Superb explanation! Simple but strong. Im trying to make it through CS in College and this is a help!
@arpitanand451
@arpitanand451 4 жыл бұрын
Past some days i am studing c language... And believe me no one is like you. Continue it sir.......
@whiteimposter9304
@whiteimposter9304 3 жыл бұрын
dud do you study in school or without?
@nullzero9224
@nullzero9224 2 жыл бұрын
Well Explained and very nice tutorial. Thank you so much
@sahilkhan1909
@sahilkhan1909 3 жыл бұрын
I absolutely like this video, this is exactly what I was looking for a couple of days.
@anandraj9859
@anandraj9859 2 жыл бұрын
Thanks for the beautiful explanation....... Thank u soooo much..
@md.jannatulnayem4328
@md.jannatulnayem4328 2 жыл бұрын
Good content...absolutely loved it 🔥
@syedmufassiriqbal4473
@syedmufassiriqbal4473 4 жыл бұрын
Very help full video , nyc explanation ✊🏻thank u sir .
@ironironowski1063
@ironironowski1063 4 жыл бұрын
HIT!! NIEWISKI GO N1ENAWIDZ1 ZNALAZŁ JEDEN PR0STY TRICK NA ZDANIE KOLOSA
@MISSONVAI
@MISSONVAI 4 жыл бұрын
HIT !! THE SLAWS HIM HIM FOUND ONE SIMPLE TRICK ON THE COLLECT'S OPINION (your comment translation)
@ukaszkiepas57
@ukaszkiepas57 4 жыл бұрын
xD
@uditmahajan555
@uditmahajan555 4 жыл бұрын
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 (:
@nathanoosterhuis6232
@nathanoosterhuis6232 3 жыл бұрын
Thank you sir, good explanation
@Clara-cj2tu
@Clara-cj2tu 3 жыл бұрын
Thank you so much!! This video is really helpful
@nml4546
@nml4546 3 жыл бұрын
Very nice, thanks, I was thinking I had to write my own sort, and actually, but this is much better.
@nbk330
@nbk330 4 жыл бұрын
very easy way of explanation
@harshitgupta424
@harshitgupta424 3 жыл бұрын
thank you soo much ! great work there .
@asmakhan541
@asmakhan541 4 жыл бұрын
Great explanation sir thank u😀😀
@siraj1512
@siraj1512 4 жыл бұрын
Very neat. Thank you
@Jack-ux3yh
@Jack-ux3yh 3 жыл бұрын
very good video,learned a lot
@sartrap1
@sartrap1 4 жыл бұрын
thank you!!! really helpful
@Inublue50
@Inublue50 3 жыл бұрын
Well taught!
@TheAbsoluteSir
@TheAbsoluteSir 3 жыл бұрын
How are you utilizing *pa and *pb in the compareInt function if you are not passing anything in the arguments from main?
@programmingwithsikander3539
@programmingwithsikander3539 3 жыл бұрын
kzbin.info/www/bejne/oniQm5mLnrljaNk It's called from inside qsort function. The above link should help you.
@laurelanderson7572
@laurelanderson7572 4 жыл бұрын
Thank you! I understand this now!
@azizprasetyo3676
@azizprasetyo3676 2 жыл бұрын
Thank u sir😇
@ViralVideos-uz1mn
@ViralVideos-uz1mn 5 жыл бұрын
very helpful video
@nguyenphucquanganh7031
@nguyenphucquanganh7031 3 жыл бұрын
thank you dude
@karamveersachdeva935
@karamveersachdeva935 4 жыл бұрын
really helpful
@rhkhandu
@rhkhandu 3 жыл бұрын
Would you please give the link of the PDF manual you followed during explanation the Syntex of qsort?
@programmingwithsikander3539
@programmingwithsikander3539 2 жыл бұрын
Its man page. man qsort
@kushbind8207
@kushbind8207 5 жыл бұрын
Thank you bro...😇😇😇😇
@tanvbd
@tanvbd 3 жыл бұрын
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_
@vishalmitra_ 4 жыл бұрын
Wooow😊♨️ I want to know reverse shotcut too
@MISSONVAI
@MISSONVAI 4 жыл бұрын
sir, 'pa' and 'pb' are void pointers then how can we pass these two pointers to Strcmp() without typecasting them to char pointer?
@programmingwithsikander3539
@programmingwithsikander3539 4 жыл бұрын
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);
@GenieChef
@GenieChef 4 жыл бұрын
Dude you are my hero! Thank you!
@qwert9313
@qwert9313 4 жыл бұрын
Thank you so much ❤️
@rathnaganesh595
@rathnaganesh595 4 жыл бұрын
great !!! Thank you :)
@surjeetsingh-tj7di
@surjeetsingh-tj7di 4 жыл бұрын
Awsome bro
@anmolraj6604
@anmolraj6604 4 жыл бұрын
Well taught
@tanvbd
@tanvbd 3 жыл бұрын
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);
@programmingwithsikander3539
@programmingwithsikander3539 3 жыл бұрын
What is type of cards, is it multidimensional array or array of pointers?
@tanvbd
@tanvbd 3 жыл бұрын
an array of pointers to structs
@axolet
@axolet 4 жыл бұрын
Thank you!
@bashmogd4468
@bashmogd4468 4 жыл бұрын
thanx very much
@purabmodi6623
@purabmodi6623 4 жыл бұрын
whats the value at address "pa" and "pb" ?
@Zambo23
@Zambo23 4 жыл бұрын
so clear, ty
@orangeshoes
@orangeshoes 4 жыл бұрын
Thank you ❤️
@skitnado25
@skitnado25 5 жыл бұрын
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); }
@programmingwithsikander3539
@programmingwithsikander3539 5 жыл бұрын
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); }
@skitnado25
@skitnado25 5 жыл бұрын
@@programmingwithsikander3539 Thank you for the clarification it worked now .
@skitnado25
@skitnado25 5 жыл бұрын
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.
@programmingwithsikander3539
@programmingwithsikander3539 5 жыл бұрын
@@skitnado25 Replace RGB_t key = {.color = input}; with RGB_t key; strcpy(key.color , input);
@wizz2681
@wizz2681 4 жыл бұрын
I'm getting a segmentation fault when I do this, any suggestion?
@programmingwithsikander3539
@programmingwithsikander3539 4 жыл бұрын
Share the code. I will help you in identifying the mistake(s)
@ohmnamo7056
@ohmnamo7056 4 жыл бұрын
bro how does pa and pb gets the address of the 2 elements in the array? thanku
@programmingwithsikander3539
@programmingwithsikander3539 4 жыл бұрын
Watch this video kzbin.info/www/bejne/oniQm5mLnrljaNk Compare function is called within the qsort function.
@ohmnamo7056
@ohmnamo7056 4 жыл бұрын
@@programmingwithsikander3539 thankss a lottt brother ..you made me understood quickly .Very understandable explanation👏👏
@Fariiis
@Fariiis 4 жыл бұрын
please work on your accent
@pratiks235
@pratiks235 2 жыл бұрын
what does his accent have to do with the knowledge imparted? i found it pretty easy to understand
Function Pointers | C Programming Tutorial
18:31
Portfolio Courses
Рет қаралды 67 М.
Мама у нас строгая
00:20
VAVAN
Рет қаралды 11 МЛН
When Cucumbers Meet PVC Pipe The Results Are Wild! 🤭
00:44
Crafty Buddy
Рет қаралды 60 МЛН
Generic data types in C
14:58
CodeVault
Рет қаралды 21 М.
Using qsort() To Sort An Array | C Programming Example
9:46
Portfolio Courses
Рет қаралды 28 М.
you will never ask about pointers again after watching this video
8:03
2.8.1  QuickSort Algorithm
13:43
Abdul Bari
Рет қаралды 3,3 МЛН
String In Char Array VS. Pointer To String Literal | C Programming Tutorial
9:58
Fast Inverse Square Root - A Quake III Algorithm
20:08
Nemean
Рет қаралды 5 МЛН
Quicksort Algorithm Implementation | C Programming Example
20:37
Portfolio Courses
Рет қаралды 64 М.
C Programming Tutorial - 41 - Sorting Arrays
12:13
thenewboston
Рет қаралды 375 М.
Using qsort() in C
10:03
WIT Solapur - Professional Learning Community
Рет қаралды 2,6 М.
135 How to use library qsort function for sorting arrays
5:58
Programming Studio
Рет қаралды 620
Мама у нас строгая
00:20
VAVAN
Рет қаралды 11 МЛН