Selection Sort Algorithm LINK PART – इसी तरह से हम Selection Sort का Algorithm लिख कर उस Algorithm के आधार पर एक Function Create कर सकते हैं। Algorithm व Function निम्नानुसार हैं-
[code] Here LIST is a Linked List Data Type and P, Q, R, S and TEMP are Linked Lists. START is a LIST Type Global Linked List Variable. SET P = R = START REPEAT Step 3 and 4 WHILE P[LINK] <> NULL S = Q = P[LINK] REPEAT Step 5 to 7 WHILE Q <> NULL IF P[INFO] = Q[INFO] IF P[LINK] = Q IF P = START P[LINK] = Q[LINK] Q[LINK] = P TEMP = P P = Q Q = TEMP START = P R = P S = Q Q = Q[LINK] ELSE P[LINK] = Q[LINK] Q[LINK] = P R[LINK] = Q TEMP = P P = Q Q = TEMP S = Q Q = Q[LINK] ELSE IF P = START TEMP = Q[LINK] Q[LINK] = P[LINK] P[LINK] = TEMP S[LINK] = P TEMP = P P = Q Q = TEMP S = Q Q = Q[LINK] START = P ELSE TEMP = Q[LINK] Q[LINK] = P[LINK] P[LINK] = TEMP R[LINK] = Q S[LINK] = P TEMP = P P = Q Q = TEMP S = Q Q = Q[LINK] ELSE S = Q Q = Q[LINK] R = P P = P[LINK] EXIT [/code] Selection Sort Function LINK PART [code] void LLSelectionSortLP() { struct LIST *P, *Q, *S, *R, TEMP; P = R = START; while(P->LINK != NULL) { S = Q = P->LINK; while(Q!=NULL) { if(P->INFO > Q->INFO) { if(P->LINK == Q) { if(P==START) { P->LINK = Q->LINK; Q->LINK = P; TEMP = P; P = Q; Q = TEMP; START = P; R = P; S = Q; Q = Q->LINK; } else { P->LINK = Q->LINK; Q->LINK = P; R->LINK = Q; TEMP = P; P = Q; Q = TEMP; S = Q Q = Q->LINK; } } else { if(P==START) { TEMP = Q->LINK; Q->LINK = P->LINK; P->LINK = TEMP; S->LINK = P; TEMP = P; P = Q; Q = TEMP; S = Q; Q = Q->LINK; START = P; } else { TEMP = Q->LINK; Q->LINK = P->LINK; P->LINK = TEMP; R->LINK = Q; S->LINK = P; TEMP = P; P = Q; Q = TEMP; S = Q; Q = Q->LINK; } } } else { S = Q; Q = Q->LINK; } } R = P; P = P->LINK; } } [/code]
ये Article इस वेबसाईट पर Selling हेतु उपलब्ध EBook Data Structure and Algorithms in Hindi से लिया गया है। इसलिए यदि ये Article आपके लिए उपयोगी रहा, तो निश्चित रूप से ये पुस्तक भी आपके लिए काफी उपयोगी साबित होगी।
Data Structure and Algorithms in Hindi | Page: 433 | Format: PDF