Linked Lists Sorting – Bubble Sort Algorithm

Linked Lists Sorting – Bubble Sort Algorithm –  किसी Linked List के लिए Bubble Sort का Algorithm निम्नानुसार होगा-

Bubble Sort Algorithm DATA PART

[code]
SET K = N
REPEAT FOR I = 0 TO N-1 STEP I = I + 1
  P = START
  Q = P[LINK]
  REPEAT FOR J = 1 TO K-1 STEP J = J + 1
    IF P[INFO] > Q[INFO]
      TEMP = P[INFO]
      P[INFO] = Q[INFO]
      Q[INFO] = TEMP
      [ End of IF Structure ]
    P = P[LINK]
    Q = Q[LINK]
  [ End of Inner Loop ]
[ End of Outer Loop ]
EXIT
[/code]

इस Algorithm में N Data Elements या NODES की कुल संख्‍या है। IJ Loop चलाने वाले Variables हैं। TEMP एक Variable है जो Data Exchanging के समय उपयोग में आता है। PQ दो Linked Lists हैं और K एक Variable है जिसका मान N की संख्‍या पर निर्भर है।

इस Algorithm के आधार पर हम निम्नानुसार Bubble Sort का Function Create कर सकते हैं जो किसी Linked List के Data Elements की Sorting करता है-

Bubble Sort Function DATA PART

[code]
void LLBubbleSortDP(int N)
{
      int I, J, K, TEMP;
      struct LIST *P, *Q;
      K = N;
      for(I=0; I<N-1; I++)
      {
            P = START;
            Q = START->LINK;
            for(J=1; J<K; J++)
            {
                  if(P->INFO > Q->INFO)
                  {
                        TEMP = P->INFO;
                        P->INFO = Q->INFO;
                        Q->INFO = TEMP;
                  }
            P = P->LINK;
            Q = Q->LINK;
      }
}
[/code]

इस Function में START Linked List के Start को Indicate करता है जो कि एक Global Variable है।

Data Structure and Algorithmes in Hindiये Article इस वेबसाईट पर Selling हेतु उपलब्‍ध EBook Data Structure and Algorithms in Hindi से लिया गया है। इसलिए यदि ये Article आपके लिए उपयोगी रहा, तो निश्चित रूप से ये पुस्तक भी आपके लिए काफी उपयोगी साबित होगी। 

Data Structure and Algorithms in Hindi | Page: 433 | Format: PDF

BUY NOW GET DEMO REVIEWS