Académique Documents
Professionnel Documents
Culture Documents
1. Set FLAG := -1
3. Read N
4. if N<0 or N>80
go to Step 2
8. Read ARR[I]
12. If NUM=ARR[I]
Set FLAG := I,
Break
13. If FLAG=-1
Else
Print, NUM, 'found at index ', FLAG, ', location ', FLAG+1
14. Exit
[Algorithm of Binary Search]
1. Set LOC := -1
3. Read N
4. if N<0 or N>80
go to Step 2
8. Read ARR[I]
LOC := MID,
Break
MIN := MID+!
Else
MAX := MID-1
15. If LOC = -1
Else
Print, NUM, ' found at index ', LOC, ' , location ', LOC+1
16. Exit
[Program to perform Bubble Sort on Integers]
1. Set N := -1
4. Read N
8. Read A[I]
12. If A[J]>A[J+1}
Call SWAP(A,J)
16. Exit
[Algorithm for the function SWAP()]
SWAP(ARR[I], N)
1. Set T := ARR[N]
3. Set ARR[N+1] := T
4. Return
[Program to perform Bubble Sort on Strings]
1. Set N := -1
4. Read N
8. Read A[I]
12. If A[J]>A[J+1}
Call SWAP(A,J)
16. Exit
[Algorithm for the function SWAP()]
SWAP(ARR[I], N)
1. Set T:=ARR[N]
2. Set ARR[N]:=ARR[N+1]
3. Set ARR[N+1]:=T
4. Return
[Algorithm to perform Insertion Sort]
1. Print, 'How many elements?'
2. Read N
3. Set N := N+1
6. Read AR[I]
7. Call INSSORT(AR, N)
11. Exit
[Algorithm for the function INSSORT()]
INSSORT(AR[], S)
3. Set T := AR[I]
4. Set J := I-1
7. J := J-1
8. Set AR[J+1] := T
12. Return
[Algorithm to demonstrate Selection Sort]
1. Print, 'How many elements?\t'
2. Read N
5. Read AR[I]
6. Call SELSORT(AR, N)
9. Print, AR[I],'\n'
10. Exit
[Algorithm for function SELSORT()]
SELSORT(AR[], SIZE)
2. Set FLAG := 0
7. Set POS := J
8. Set FLAG := 1
16. Return
[Algorithm to demonstrate queues using arrays]
1. Set FRONT := -1
2. Set REAR := -1
5. Read CH
Print, 'Overflow'
Exit
Set FRONT := 0
Set REAR := 0
Read ARR[REAR]
Else
REAR := REAR+1
Read ARR[REAR]
8. Break
9. If CH =2, follow steps 10-11
Print, 'Underflow'
Exit
Else
FRONT := FRONT+1
11. Break
13. Exit
[Algorithm for the function DISPLAY()]
DISPLAY( A[], F, R)
1. Print,'\n'
4. Return
[Algorithm to demonstrate circular queues using arrays]
1. Set FRONT := -1
2. Set REAR := -1
5. Read CH
Print, 'Overflow'
Exit
Set FRONT := 0
Set REAR := 0
Read ARR[REAR]
Set REAR := 0
Read ARR[REAR]
Else
REAR := REAR+1
Print, 'Enter the item to be inserted:'
Read ARR[REAR]
8. Break
Print, 'Underflow'
Exit
Set FRONT := -1
Set REAR := -1
Set FRONT := 0
Else
FRONT := 0
11. Break
1. Print,'\n'
2. If F <= R, then
Else
3. Return
[Algorithm to demonstrate Stacks in Linked List]
[Create a NODE data type with elements (INT)INFO, (POINTER OF NODE)DATA]
1. Set CH := 'y'
5. Read INF
7. If NEWPTR=NULL, then
Exit
8. Call PUSH(NEWPTR)
9. Call DISPLAY(TOP)
11. Read CH
13. Read CH
19. Read CH
20. Exit
[Algorithm for the function CREATENEWNODE()]
NODE *CREATENEWNODE(N)
2. Set PTR->INFO := N
4. Return PTR
[Algorithm for the function PUSH()]
PUSH(*NP)
1. If TOP=NULL, then
Set TOP := NP
Else
Set TOP := NP
2. Return
[Algorithm for the function DISPLAY()]
DISPLAY(*NP)
2. Print, NP->INFO,'-->'
3. Set NP:=NP->NEXT
4. Print,'!!!\n'
5. Return
[Algorithm for the function POP()]
POP()
1. If TOP=NULL, then
Print, 'Underflow!!'
Exit
Else
Set PTR:=TOP
Set TOP:=TOP->NEXT
Delete PTR
2. Return
[Algorithm to demonstrate Linked List Traversal]
[Create a NODE data type with elements (INT)INFO, (POINTER OF NODE)DATA]
1. Print,'Node creation...\n'
2. Set CH:='y'
3. Set TOP:=NULL
6. Read I
7. Set PTR:=CREATENEWNODE(I)
8. Set PTR->NEXT:=TOP
9. Set TOP:=PTR
11. Read CH
14. Exit
[Algorithm for the function CREATENEWNODE()]
NODE *CREATENEWNODE(N)
2. Set PTR->INFO := N
4. Return PTR
[Algorithm for the function DISPLAY()]
DISPLAY(*NP)
2. Print, NP->INFO,'-->'
3. Set NP:=NP->NEXT
4. Print,'!!!\n'
5. Return
[Algorithm to demonstrate Linked List Search]
[Create a NODE data type with elements (INT)INFO, (POINTER OF NODE)DATA]
2. Set CH:='y'
3. Set TOP:=NULL
6. Read I
7. Set PTR:=CREATENEWNODE(I)
8. Set PTR->NEXT:=TOP
9. Set TOP:=PTR
11. Read CH
14. Read I
Else
1. Set I:=1
3. If NP->INFO=N, then
4. Return I
5. Set NP:=NP->NEXT
6. Set I:=I+1
7. Return -1
[Algorithm for the function CREATENEWNODE()]
NODE *CREATENEWNODE(N)
2. Set PTR->INFO := N
4. Return PTR
[Algorithm to demonstrate Linked List Insertion]
[Create a NODE data type with elements (INT)INFO, (POINTER OF NODE)DATA]
2. Set CH:='y'
3. Set TOP:=NULL
6. Read I
7. Set PTR:=CREATENEWNODE(I)
8. Set PTR->NEXT:=TOP
9. Set TOP:=PTR
11. Read CH
14. Read I
17. Read I
19. Print, '\n\nAfter performing the insertion, the Linked List is...\n'
21. Exit
[Algorithm for the function CREATENEWNODE()]
NODE *CREATENEWNODE(N)
2. Set PTR->INFO := N
4. Return PTR
[Algorithm for the function INSERT()]
INSERT(*PTR, LOC)
1. Set *NP:=NULL
2. If LOC=1, then
Set PTR->NEXT:=TOP
Set TOP:=PTR
Return
Else
a. Set SAVE:=NP
b. Set NP:=NP->NEXT
c. If I=LOC, then
Set SAVE->NEXT:=PTR
Set PTR->NEXT:=NP
Return
3. Set SAVE->NEXT:=PTR
4. Return
[Algorithm for the function DISPLAY()]
DISPLAY(*N)
2. Print, N->INFO,'-->'
3. Set N:=N->NEXT
4. Print,'!!!\n'
5. Return
[Algorithm to demonstrate Linked List Deletion]
[Create a NODE data type with elements (INT)INFO, (POINTER OF NODE)DATA]
2. Set CH:='y'
3. Set TOP:=NULL
6. Read I
7. Set PTR:=CREATENEWNODE(I)
8. Set PTR->NEXT:=TOP
9. Set TOP:=PTR
11. Read CH
14. Read I
Else
Print, '\n', I, ' found at position ', POS, ' and deletion accomplished successfully.'
17. Print, '\nThe Linked List after the whole procedure is...\n'
2. Set PTR->INFO := N
4. Return PTR
[Algorithm for the function DISPLAY()]
DISPLAY(*N)
2. Print, N->INFO,'-->'
3. Set N:=N->NEXT
4. Print,'!!!\n'
5. Return
[Algorithm for the function SEARCHDEL()]
INT SEARCHDEL(N)
1. Set *NP:=TOP
2. If NP->INFO=N, then
Set TOP:=TOP->NEXT
Return 1
3. Set I:=2
4. Set SAVE:=TOP
5. Set NP:=TOP->NEXT
7. If NP->INFO=N, then
Set SAVE->NEXT=NP->NEXT
Return I
8. Set SAVE:=NP
9. Set NP:=NP->NEXT
11. Return -1
[Algorithm demonstrating Quick Sort]
1. Set I:=0
2. Set N:=0
4. Read N
7. Read ARR[I]
8. Call SORT(ARR,0,N)
12. Exit
[Algorithm of the function SWAP()]
SWAP(*A, *B)
1. Set T:=*A
2. Set *A:=*B
3. Set *B:=T
[Algorithm of SORT()]
SORT(ARR[], BEG, END)
1. Set K:=0
2. If END>BEG+1, then
Set PIV:=ARR[BEG]
Set L:=BEG+1
Set R:=END
a. If ARR[I]<=PIV, then
Set L:=L+1
Else
2. Set CH:='y'
5. Read ITEM
7. If RES=-1. then
Exit
11. Read CH
13. Read CH
Exit
20. Read CH
21. Exit
[Algorithm for the function PUSH()]
INT PUSH(STACK[], &TOP, ELE)
1. If TOP=SIZE-1, then
return -1
Else
TOP:=TOP+1
STACK[TOP]:=ELE
2. Return 0
[Algorithm for the function DISPLAY()]
DISPLAY(STACK[], TOP)
4. Return
[Algorithm for the function POP()]
POP(STACK[], &TOP]
1. If TOP=-1, then
Return -1
Else
RET:=STACK[TOP]
TOP:=TOP-1
2. Return RET
INDEX
NOTE: Each program unit contains Algorithm, Flowchart, Program Code and Output in the
order specified.
DATA STRUCTURES PRACTICAL
FILE
Submitted to:
Mr. Rahul Aggarwal
Submitted by:
Anamjyot Kaur
08104006
Elec & Comm Engg