├── MPL ├── A13 │ ├── z.asm │ └── A13.asm ├── A8 │ ├── file1.txt │ └── file2.txt ├── A7 │ ├── data.txt │ ├── A7 │ ├── A7.o │ ├── macro.asm │ └── A7.asm ├── A5 │ ├── myfile.txt │ ├── A5_file1 │ ├── A5_file.o │ ├── A5_file1.o │ ├── A5_file2.o │ ├── macro.asm │ ├── A5_file1.asm │ └── A5_file2.asm ├── A6 │ ├── A6 │ ├── A6.o │ └── A6.asm ├── A10 │ ├── A10 │ ├── A10.o │ └── A10.asm ├── A12 │ ├── A12 │ ├── A12.o │ └── A12.asm ├── A11 │ ├── A11_1.asm │ └── A11_2.asm ├── A14 │ └── A14.asm ├── A4 │ ├── A4a.asm │ └── A4b.asm ├── A1 │ └── A1.asm ├── A9 │ └── A9f.asm ├── A2 │ ├── A2-1.asm │ └── A2-2.asm └── A3 │ └── A3.asm ├── README.md └── Data Structures and Algorithms ├── 1A ├── 7C.cpp ├── 6C.cpp ├── 3A.cpp ├── 5B.cpp ├── 10E.cpp ├── 2A.py ├── 8D.cpp ├── README.md ├── 12F.cpp ├── 4B.cpp ├── 11F.cpp └── 9D.cpp /MPL/A13/z.asm: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /MPL/A8/file1.txt: -------------------------------------------------------------------------------- 1 | Hello 2 | Welcome to MCOE 3 | -------------------------------------------------------------------------------- /MPL/A8/file2.txt: -------------------------------------------------------------------------------- 1 | Computer Enginerring Department 2 | -------------------------------------------------------------------------------- /MPL/A7/data.txt: -------------------------------------------------------------------------------- 1 | 4 2 | 5 3 | 1 4 | 2 5 | 3 6 | 7 | -------------------------------------------------------------------------------- /MPL/A5/myfile.txt: -------------------------------------------------------------------------------- 1 | "Welcome" 2 | Computer Engineering 3 | PES MCOE, 4 | Codyapa 5 | -------------------------------------------------------------------------------- /MPL/A6/A6: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vishwajeet-Londhe/SPPU-CSE-SEM4-Codes/HEAD/MPL/A6/A6 -------------------------------------------------------------------------------- /MPL/A7/A7: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vishwajeet-Londhe/SPPU-CSE-SEM4-Codes/HEAD/MPL/A7/A7 -------------------------------------------------------------------------------- /MPL/A10/A10: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vishwajeet-Londhe/SPPU-CSE-SEM4-Codes/HEAD/MPL/A10/A10 -------------------------------------------------------------------------------- /MPL/A12/A12: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vishwajeet-Londhe/SPPU-CSE-SEM4-Codes/HEAD/MPL/A12/A12 -------------------------------------------------------------------------------- /MPL/A6/A6.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vishwajeet-Londhe/SPPU-CSE-SEM4-Codes/HEAD/MPL/A6/A6.o -------------------------------------------------------------------------------- /MPL/A7/A7.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vishwajeet-Londhe/SPPU-CSE-SEM4-Codes/HEAD/MPL/A7/A7.o -------------------------------------------------------------------------------- /MPL/A10/A10.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vishwajeet-Londhe/SPPU-CSE-SEM4-Codes/HEAD/MPL/A10/A10.o -------------------------------------------------------------------------------- /MPL/A12/A12.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vishwajeet-Londhe/SPPU-CSE-SEM4-Codes/HEAD/MPL/A12/A12.o -------------------------------------------------------------------------------- /MPL/A5/A5_file1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vishwajeet-Londhe/SPPU-CSE-SEM4-Codes/HEAD/MPL/A5/A5_file1 -------------------------------------------------------------------------------- /MPL/A5/A5_file.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vishwajeet-Londhe/SPPU-CSE-SEM4-Codes/HEAD/MPL/A5/A5_file.o -------------------------------------------------------------------------------- /MPL/A5/A5_file1.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vishwajeet-Londhe/SPPU-CSE-SEM4-Codes/HEAD/MPL/A5/A5_file1.o -------------------------------------------------------------------------------- /MPL/A5/A5_file2.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vishwajeet-Londhe/SPPU-CSE-SEM4-Codes/HEAD/MPL/A5/A5_file2.o -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

SPPU CSE SEM-IV Practical Codes

2 | 3 |

4 | 5 | WhatsApp Channel for Quick Updates 6 | 7 |

8 | 9 | **Join our Telegram channel [here!](https://t.me/SPPU_TE_BE_COMP)** 10 | 11 | **All SE Codes of following subjects available with notes** 12 | 13 | DSA 14 | MPL 15 | 16 |
17 |

18 |
19 | 20 | > Click :star: if you like the repo. Pull Requests are highly appreciated. 21 | -------------------------------------------------------------------------------- /MPL/A11/A11_1.asm: -------------------------------------------------------------------------------- 1 | .model small 2 | .stack 100 3 | .data 4 | msg db 10,13,'---------------THIS IS SINE WAVE------------------$' 5 | 6 | x dd 00 7 | xad dd 3.0 8 | one80 dd 180.0 9 | thirty dd 30.0 10 | fifty dd 50.0 11 | xcursor dd 00 12 | ycursor dt 00 13 | count dw 360 14 | x1 dw 0 15 | 16 | .code 17 | .386 18 | main: 19 | 20 | mov ax,@data 21 | mov ds,ax 22 | 23 | mov ah,00 24 | mov al,6 25 | int 10h 26 | 27 | up1: 28 | finit 29 | Fldpi 30 | Fdiv one80 31 | Fmul x 32 | Fsin 33 | Fmul thirty 34 | 35 | Fld fifty 36 | Fsub ST,ST(1) 37 | 38 | Fbstp ycursor 39 | lea si,ycursor 40 | 41 | mov ah,0ch 42 | mov al,01h 43 | mov bh,0h 44 | mov cx,x1 45 | mov dx,[si] 46 | int 10h 47 | 48 | inc x1 49 | Fld x 50 | Fadd xad 51 | Fst x 52 | dec count 53 | jnz up1 54 | 55 | mov ah,09h 56 | lea dx,msg 57 | int 21h 58 | 59 | mov ah,4ch 60 | int 21h 61 | end main 62 | -------------------------------------------------------------------------------- /MPL/A11/A11_2.asm: -------------------------------------------------------------------------------- 1 | .model small 2 | .stack 100 3 | .data 4 | msg db 10,13,'---------------THIS IS COS WAVE------------------$' 5 | 6 | x dd 00 7 | xad dd 3.0 8 | one80 dd 180.0 9 | thirty dd 30.0 10 | fifty dd 50.0 11 | xcursor dd 00 12 | ycursor dt 00 13 | count dw 360 14 | x1 dw 0 15 | 16 | .code 17 | .386 18 | main: 19 | 20 | mov ax,@data 21 | mov ds,ax 22 | 23 | mov ah,00 24 | mov al,6 25 | int 10h 26 | 27 | up1: 28 | finit 29 | Fldpi 30 | Fdiv one80 31 | Fmul x 32 | Fcos 33 | Fmul thirty 34 | 35 | Fld fifty 36 | Fsub ST,ST(1) 37 | 38 | Fbstp ycursor 39 | lea si,ycursor 40 | 41 | mov ah,0ch 42 | mov al,01h 43 | mov bh,0h 44 | mov cx,x1 45 | mov dx,[si] 46 | int 10h 47 | 48 | inc x1 49 | Fld x 50 | Fadd xad 51 | Fst x 52 | dec count 53 | jnz up1 54 | 55 | mov ah,09h 56 | lea dx,msg 57 | int 21h 58 | 59 | mov ah,4ch 60 | int 21h 61 | end main 62 | -------------------------------------------------------------------------------- /MPL/A5/macro.asm: -------------------------------------------------------------------------------- 1 | ;macro.asm 2 | ;macros as per 64 bit conventions 3 | 4 | %macro read 2 5 | mov rax,0 ;read 6 | mov rdi,0 ;stdin/keyboard 7 | mov rsi,%1 ;buf 8 | mov rdx,%2 ;buf_len 9 | syscall 10 | %endmacro 11 | 12 | %macro print 2 13 | mov rax,1 ;print 14 | mov rdi,1 ;stdout/screen 15 | mov rsi,%1 ;msg 16 | mov rdx,%2 ;msg_len 17 | syscall 18 | %endmacro 19 | 20 | %macro fopen 1 21 | mov rax,2 ;open 22 | mov rdi,%1 ;filename 23 | mov rsi,2 ;mode RW 24 | mov rdx,0777o ;File permissions 25 | syscall 26 | %endmacro 27 | 28 | %macro fread 3 29 | mov rax,0 ;read 30 | mov rdi,%1 ;filehandle 31 | mov rsi,%2 ;buf 32 | mov rdx,%3 ;buf_len 33 | syscall 34 | %endmacro 35 | 36 | %macro fwrite 3 37 | mov rax,1 ;write/print 38 | mov rdi,%1 ;filehandle 39 | mov rsi,%2 ;buf 40 | mov rdx,%3 ;buf_len 41 | syscall 42 | %endmacro 43 | 44 | %macro fclose 1 45 | mov rax,3 ;close 46 | mov rdi,%1 ;file handle 47 | syscall 48 | %endmacro 49 | 50 | %macro exit 0 51 | print nline,nline_len 52 | mov rax,60 ;exit 53 | mov rdi,0 54 | syscall 55 | %endmacro 56 | -------------------------------------------------------------------------------- /MPL/A7/macro.asm: -------------------------------------------------------------------------------- 1 | ;macro.asm 2 | ;macros as per 64 bit conventions 3 | 4 | %macro read 2 5 | mov rax,0 ;read 6 | mov rdi,0 ;stdin/keyboard 7 | mov rsi,%1 ;buf 8 | mov rdx,%2 ;buf_len 9 | syscall 10 | %endmacro 11 | 12 | %macro print 2 13 | mov rax,1 ;print 14 | mov rdi,1 ;stdout/screen 15 | mov rsi,%1 ;msg 16 | mov rdx,%2 ;msg_len 17 | syscall 18 | %endmacro 19 | 20 | %macro fopen 1 21 | mov rax,2 ;open 22 | mov rdi,%1 ;filename 23 | mov rsi,2 ;mode RW 24 | mov rdx,0777o ;File permissions 25 | syscall 26 | %endmacro 27 | 28 | %macro fread 3 29 | mov rax,0 ;read 30 | mov rdi,%1 ;filehandle 31 | mov rsi,%2 ;buf 32 | mov rdx,%3 ;buf_len 33 | syscall 34 | %endmacro 35 | 36 | %macro fwrite 3 37 | mov rax,1 ;write/print 38 | mov rdi,%1 ;filehandle 39 | mov rsi,%2 ;buf 40 | mov rdx,%3 ;buf_len 41 | syscall 42 | %endmacro 43 | 44 | %macro fclose 1 45 | mov rax,3 ;close 46 | mov rdi,%1 ;file handle 47 | syscall 48 | %endmacro 49 | 50 | %macro exit 0 51 | print nline,nline_len 52 | mov rax,60 ;exit 53 | mov rdi,0 54 | syscall 55 | %endmacro 56 | -------------------------------------------------------------------------------- /MPL/A14/A14.asm: -------------------------------------------------------------------------------- 1 | code segment 2 | 3 | assume cs:code,ds:code 4 | start: mov ax,cs 5 | mov ds,ax 6 | mov cl,0 7 | mov ch,0 8 | 9 | task1: inc cl 10 | cmp cl,09 11 | je exit 12 | mov ax,0b800h 13 | mov es,axz.asm 14 | mov si,1830 15 | 16 | mov al,'*' 17 | mov ah,93h 18 | mov es:[si],ax 19 | inc bl 20 | mov al,bl 21 | add al,30h 22 | mov ah,93h 23 | inc si 24 | inc si 25 | 26 | mov es:[si],ax 27 | call delay 28 | 29 | jmp task2 30 | 31 | 32 | 33 | task2: inc ch 34 | cmp ch,09 35 | je exit 36 | mov ax,0b800h 37 | mov es,ax 38 | mov si,840 39 | mov al,'$' 40 | mov ah,0A1h 41 | mov es:[si],ax 42 | inc bh 43 | mov al,bh 44 | add al,30h 45 | mov ah,0A1h 46 | inc si 47 | inc si 48 | 49 | mov es:[si],ax 50 | call delay 51 | 52 | jmp task1 53 | 54 | 55 | delay proc near 56 | mov ax,0fffh 57 | d2:mov dx,0fffh 58 | d1:nop 59 | nop 60 | nop 61 | nop 62 | dec dx 63 | jnz d1 64 | dec ax 65 | jnz d2 66 | ret 67 | endp 68 | 69 | 70 | 71 | exit: 72 | mov ah,4ch 73 | int 21h 74 | 75 | code ends 76 | end start 77 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/1A: -------------------------------------------------------------------------------- 1 | size=int(input("Enter the table size :")) 2 | n=int(input("\nEnter no .of records to be inserted :")) 3 | hash_table=[-1]*size 4 | def linear_probing(telephone_no): 5 | for i in range (size): 6 | index=(telephone_no+i)%size 7 | if(hash_table[index]==-1): 8 | hash_table[index]=(telephone_no) 9 | print("\nRecord Inserted") 10 | break 11 | else: 12 | print("Table Full , Record Cannot be Inserted") 13 | def Quadratic(telephone_no): 14 | i=0 15 | for i in range(size): 16 | index=(telephone_no%size +i*i)%size 17 | if(hash_table[index]==-1): 18 | hash_table[index]=(telephone_no) 19 | print("Record Inserted") 20 | break 21 | else: 22 | i+=1 23 | if(i==size): 24 | print("Element Cannot be inserted") 25 | def search(telephone_no): 26 | count=1 27 | for i in range (size): 28 | index=(telephone+i)%size 29 | if(hash_table[index]==telephone): 30 | print("Element Found at index ",index) 31 | print("Required record :",hash_table[index]) 32 | print("No.of comparisons =",count) 33 | break 34 | elif(hash_table[index]!=tele): 35 | i+=1 36 | count+=1 37 | else: 38 | print("Record not found") 39 | def display(): 40 | print("Index Telephone number ") 41 | for i in range (size): 42 | if(hash_table[i]!=-1): 43 | print(i," ",hash_table[i]) 44 | while(True): 45 | choice=int(input("\n1.Insert the record using linear probing\n2.Insert record using Quadratic probing \n3.Search\n4.Display record \n5]Exit")) 46 | if(choice==1): 47 | for i in range(n): 48 | teleno=int(input("Enter the telephone_no :")) 49 | linear_probing(teleno) 50 | elif(choice==2): 51 | for i in range(n): 52 | teleno=int(input("Enter the telephone_no :")) 53 | Quadratic(teleno) 54 | elif(choice==3): 55 | tele_num=int(input("Enter the number to be searched :")) 56 | search(telephone_num) 57 | if(choice==4): 58 | display() 59 | else: 60 | print("Program Exited") 61 | 62 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/7C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | int main() 5 | { 6 | int n, i, j, k, row, col, mincost = 0, min; 7 | char op; 8 | 9 | cout << "Enter no. of vertices: "; 10 | cin >> n; 11 | 12 | int cost[n][n]; 13 | int visit[n]; 14 | 15 | for (i = 0; i < n; i++) 16 | visit[i] = 0; 17 | 18 | for (i = 0; i < n; i++) 19 | { 20 | for (j = 0; j < n; j++) 21 | { 22 | cost[i][j] = -1; 23 | } 24 | } 25 | 26 | for (i = 0; i < n; i++) 27 | { 28 | for (j = i + 1; j < n; j++) 29 | { 30 | cout << "Do you want an edge between " << i + 1 << " and " << j + 1 << ": "; 31 | // use 'i' & 'j' if your vertices start from 0 32 | cin >> op; 33 | 34 | if (op == 'y' || op == 'Y') 35 | { 36 | cout << "Enter weight: "; 37 | cin >> cost[i][j]; 38 | cost[j][i] = cost[i][j]; 39 | } 40 | } 41 | } 42 | 43 | visit[0] = 1; 44 | 45 | for (k = 0; k < n - 1; k++) 46 | { 47 | min = 999; 48 | 49 | for (i = 0; i < n; i++) 50 | { 51 | for (j = 0; j < n; j++) 52 | { 53 | if (visit[i] == 1 && visit[j] == 0) 54 | { 55 | if (cost[i][j] != -1 && min > cost[i][j]) 56 | { 57 | min = cost[i][j]; 58 | row = i; 59 | col = j; 60 | } 61 | } 62 | } 63 | } 64 | 65 | mincost += min; 66 | visit[col] = 1; 67 | cost[row][col] = cost[col][row] = -1; 68 | 69 | cout << row + 1 << "->" << col + 1 << endl; 70 | // use 'row' & 'col' if your vertices start from 0 71 | } 72 | 73 | cout << "\nMin. Cost: " << mincost; 74 | return 0; 75 | } 76 | -------------------------------------------------------------------------------- /MPL/A13/A13.asm: -------------------------------------------------------------------------------- 1 | code segment 2 | assume cs:code 3 | org 100h 4 | jmp initze 5 | savint dd ? 6 | msg db 10,13,'$' 7 | hour db ? 8 | min db ? 9 | sec db ? 10 | 11 | testnum:push ax 12 | push bx 13 | push cx 14 | push dx 15 | push cs 16 | push es 17 | push si 18 | push di 19 | call time 20 | exit:pop di 21 | pop si 22 | pop es 23 | pop ds 24 | pop dx 25 | pop cx 26 | pop bx 27 | pop ax 28 | jmp cs:savint 29 | convert proc 30 | and al,0f0h 31 | ror al,4 32 | add al,30h 33 | mov ah,02h 34 | mov dl,al 35 | int 21h 36 | mov al,dh 37 | and al,0fh 38 | add al,30h 39 | mov ah,02h 40 | mov dl,al 41 | int 21h 42 | ret 43 | endp 44 | time proc 45 | mov ah,02h 46 | int 1ah 47 | mov hour,ch 48 | mov min,cl 49 | mov sec,dh 50 | mov al,hour 51 | mov dh,hour 52 | call convert 53 | mov ah,02h 54 | mov dl,':' 55 | int 21h 56 | mov al,min 57 | mov dh,min 58 | call convert 59 | mov ah,02h 60 | mov dl,':' 61 | int 21h 62 | mov al,sec 63 | mov dh,sec 64 | call convert 65 | mov ah,09h 66 | lea dx,msg 67 | int 21h 68 | call tone 69 | ret 70 | endp 71 | 72 | tone proc 73 | mov al,182 74 | out 43h,al 75 | mov ax,4560 76 | out 42h,al 77 | mov al,ah 78 | out 42h,al 79 | in al,61h 80 | or al,00000011b 81 | out 61h,al 82 | mov bx,1255 83 | 84 | .pause1: 85 | mov cx,65535 86 | 87 | .pause2: 88 | dec cx 89 | jne .pause2 90 | dec bx 91 | jne .pause1 92 | in al,61h 93 | and al,11111100b 94 | out 61h,al 95 | ret 96 | endp 97 | 98 | 99 | initze proc 100 | push cs 101 | pop ds 102 | cli 103 | mov ah,35h 104 | mov al,08h 105 | int 21h 106 | 107 | mov word ptr savint,bx 108 | mov word ptr savint+2,es 109 | mov ah,25h 110 | mov al,08h 111 | mov dx,offset testnum 112 | int 21h 113 | mov ah,31h 114 | mov dx,offset initze 115 | sti 116 | int 21h 117 | endp 118 | code ends 119 | end 120 | 121 | -------------------------------------------------------------------------------- /MPL/A4/A4a.asm: -------------------------------------------------------------------------------- 1 | 2 | ;********************************************* 3 | section .data 4 | 5 | welmsg db 10,'Multiplication using successive addition',10 6 | welmsg_len equ $-welmsg 7 | 8 | nummsg db 10,'Enter two digits of Number::' 9 | nummsg_len equ $-nummsg 10 | 11 | resmsg db 10,'Multiplication of elements::' 12 | resmsg_len equ $-resmsg 13 | 14 | blankmsg db 10,'',10 15 | blank_len equ $-blankmsg 16 | 17 | ;**********.bss Section********************** 18 | section .bss 19 | 20 | numascii resb 03 21 | num1 resb 02 22 | num2 resb 02 23 | result resb 01 24 | dispbuff resb 04 25 | 26 | %macro display 2 27 | mov rax,01 28 | mov rdi,01 29 | mov rsi,%1 30 | mov rdx,%2 31 | syscall 32 | %endmacro 33 | 34 | %macro accept 2 35 | mov rax,00 36 | mov rdi,00 37 | mov rsi,%1 38 | mov rdx,%2 39 | syscall 40 | %endmacro 41 | ;**********.text Section********************** 42 | section .text 43 | 44 | global _start 45 | 46 | _start: 47 | 48 | display welmsg,welmsg_len 49 | 50 | display nummsg,nummsg_len 51 | accept numascii,3 52 | call packnum 53 | mov byte[num1],bl 54 | 55 | display nummsg,nummsg_len 56 | accept numascii,3 57 | call packnum 58 | mov byte[num2],bl 59 | 60 | mov cx,[num2] 61 | mov edx,00h ;Temporary Addition 62 | mov eax,[num1] 63 | 64 | addup: 65 | add edx,eax 66 | loop addup 67 | 68 | mov [result],edx 69 | 70 | display resmsg,resmsg_len 71 | mov ebx,[result] 72 | 73 | call disp16_proc 74 | display blankmsg,blank_len 75 | exit: 76 | mov rax,60 77 | mov rbx,00 78 | syscall 79 | 80 | ;**********Packnum Procedure********************** 81 | packnum: 82 | mov bl,0 83 | mov ecx,02 84 | mov esi,numascii 85 | up1: 86 | rol bl,04 87 | mov al,[esi] 88 | cmp al,39h 89 | jbe skip1 90 | sub al,07h 91 | skip1: 92 | sub al,30h 93 | add bl,al 94 | inc esi 95 | loop up1 96 | ret 97 | ;**********Display Procedure********************** 98 | disp16_proc: 99 | mov ecx,4 100 | mov edi,dispbuff 101 | dup1: 102 | rol bx,4 103 | mov al,bl 104 | and al,0fh 105 | cmp al,09 106 | jbe dskip 107 | add al,07h 108 | dskip: 109 | add al,30h 110 | mov [edi],al 111 | inc edi 112 | loop dup1 113 | display dispbuff,4 114 | ret 115 | 116 | -------------------------------------------------------------------------------- /MPL/A4/A4b.asm: -------------------------------------------------------------------------------- 1 | 2 | ;********************************************* 3 | section .data 4 | 5 | welmsg db 10,'Multiplication using Add & Shift method',10 6 | welmsg_len equ $-welmsg 7 | 8 | nummsg db 10,'Enter two digits of Number::' 9 | nummsg_len equ $-nummsg 10 | 11 | resmsg db 10,'Multiplication of elements::' 12 | resmsg_len equ $-resmsg 13 | 14 | blankmsg db 10,'',10 15 | blank_len equ $-blankmsg 16 | ;**********.bss Section********************** 17 | section .bss 18 | 19 | 20 | numascii resb 03 21 | num1 resb 02 22 | num2 resb 02 23 | result resb 02 24 | dispbuff resb 04 25 | 26 | %macro display 2 27 | mov rax,01 28 | mov rdi,01 29 | mov rsi,%1 30 | mov rdx,%2 31 | syscall 32 | %endmacro 33 | 34 | %macro accept 2 35 | mov rax,00 36 | mov rdi,00 37 | mov rsi,%1 38 | mov rdx,%2 39 | syscall 40 | %endmacro 41 | 42 | ;**********.text Section********************** 43 | section .text 44 | 45 | global _start 46 | 47 | _start: 48 | 49 | display welmsg,welmsg_len 50 | display nummsg,nummsg_len 51 | accept numascii,3 52 | call packnum 53 | mov byte[num1],bl 54 | 55 | display nummsg,nummsg_len 56 | accept numascii,3 57 | call packnum 58 | mov byte[num2],bl 59 | 60 | mov al,[num1] 61 | 62 | mov cl,0 63 | mov edx,0 64 | mov edx,08h 65 | 66 | addup: 67 | rcr al,01 68 | jnc next1 69 | mov bh,00h 70 | shl bx,cl 71 | add [result],bx 72 | mov bl,[num2] 73 | next1: 74 | inc cl 75 | dec edx 76 | jnz addup 77 | 78 | display resmsg,resmsg_len 79 | mov ebx,[result] 80 | call disp16_proc 81 | 82 | display blankmsg,blank_len 83 | exit: 84 | mov rax,60 85 | mov rbx,00 86 | syscall 87 | 88 | ;**********Packnum Procedure********************** 89 | packnum: 90 | mov bl,0 91 | mov ecx,02 92 | mov esi,numascii 93 | up1: 94 | rol bl,04 95 | mov al,[esi] 96 | cmp al,39h 97 | jbe skip1 98 | sub al,07h 99 | skip1: 100 | sub al,30h 101 | add bl,al 102 | inc esi 103 | loop up1 104 | ret 105 | 106 | ;**********Display Procedure********************** 107 | disp16_proc: 108 | mov ecx,4 109 | mov edi,dispbuff 110 | dup1: 111 | rol bx,4 112 | mov al,bl 113 | and al,0fh 114 | cmp al,09 115 | jbe dskip 116 | add al,07h 117 | dskip: 118 | add al,30h 119 | mov [edi],al 120 | inc edi 121 | loop dup1 122 | display dispbuff,4 123 | ret 124 | 125 | -------------------------------------------------------------------------------- /MPL/A5/A5_file1.asm: -------------------------------------------------------------------------------- 1 | ;Assignment Name :X86/64 Assembly language program (ALP) to find 2 | ; a) Number of Blank spaces 3 | ; b) Number of lines 4 | ; c) Occurrence of a particular character. 5 | ;Accept the data from the text file. The text file has to be accessed during Program_1 execution. 6 | ;Write FAR PROCEDURES in Program_2 for the rest of the processing. 7 | ;Use of PUBLIC/GLOBAL and EXTERN directives is mandatory. 8 | ;------------------------------------------------------------------------ 9 | 10 | extern far_proc ; [ FAR PROCRDURE 11 | ; USING EXTERN DIRECTIVE ] 12 | 13 | global filehandle, char, buf, abuf_len 14 | 15 | %include "macro.asm" 16 | 17 | ;------------------------------------------------------------------------ 18 | section .data 19 | nline db 10 20 | nline_len equ $-nline 21 | 22 | ano db 10,10,10,10,"----String Operation using Far Procedure----" 23 | db 10,"---------------------------------------------------",10 24 | ano_len equ $-ano 25 | 26 | filemsg db 10,"Enter filename for string operation : " 27 | filemsg_len equ $-filemsg 28 | 29 | charmsg db 10,"Enter character to search : " 30 | charmsg_len equ $-charmsg 31 | 32 | errmsg db 10,"ERROR in opening File...",10 33 | errmsg_len equ $-errmsg 34 | 35 | exitmsg db 10,10,"Exit from program...",10,10 36 | exitmsg_len equ $-exitmsg 37 | 38 | ;--------------------------------------------------------------------------- 39 | section .bss 40 | buf resb 4096 41 | buf_len equ $-buf ; buffer initial length 42 | 43 | filename resb 50 44 | char resb 2 45 | 46 | filehandle resq 1 47 | abuf_len resq 1 ; actual buffer length 48 | 49 | ;-------------------------------------------------------------------------- 50 | section .text 51 | global _start 52 | 53 | _start: 54 | print ano,ano_len ;assignment no. 55 | 56 | print filemsg,filemsg_len 57 | read filename,50 58 | dec rax 59 | mov byte[filename + rax],0 ; blank char/null char 60 | 61 | print charmsg,charmsg_len 62 | read char,2 63 | 64 | fopen filename ; on succes returns handle 65 | cmp rax,-1H ; on failure returns -1 66 | jle Error 67 | mov [filehandle],rax 68 | 69 | fread [filehandle],buf, buf_len 70 | mov [abuf_len],rax 71 | 72 | call far_proc 73 | jmp Exit 74 | 75 | Error: print errmsg, errmsg_len 76 | 77 | Exit: print exitmsg,exitmsg_len 78 | exit 79 | ;-------------------------------------------------------------------------------- 80 | 81 | -------------------------------------------------------------------------------- /MPL/A5/A5_file2.asm: -------------------------------------------------------------------------------- 1 | ;--------------------------------------------------------------------- 2 | section .data 3 | nline db 10,10 4 | nline_len: equ $-nline 5 | 6 | smsg db 10,"No. of spaces are : " 7 | smsg_len: equ $-smsg 8 | 9 | nmsg db 10,"No. of lines are : " 10 | nmsg_len: equ $-nmsg 11 | 12 | cmsg db 10,"No. of character occurances are : " 13 | cmsg_len: equ $-cmsg 14 | 15 | ;--------------------------------------------------------------------- 16 | section .bss 17 | 18 | scount resq 1 19 | ncount resq 1 20 | ccount resq 1 21 | 22 | char_ans resb 16 23 | 24 | ;--------------------------------------------------------------------- 25 | global far_proc 26 | 27 | extern filehandle, char, buf, abuf_len 28 | 29 | %include "macro.asm" 30 | ;--------------------------------------------------------------------- 31 | section .text 32 | global _main 33 | _main: 34 | 35 | far_proc: ;FAR Procedure 36 | 37 | xor rax,rax 38 | xor rbx,rbx 39 | xor rcx,rcx 40 | xor rsi,rsi 41 | 42 | mov bl,[char] 43 | mov rsi,buf 44 | mov rcx,[abuf_len] 45 | 46 | again: mov al,[rsi] 47 | 48 | case_s: cmp al,20h ;space : 32 (20H) 49 | jne case_n 50 | inc qword[scount] 51 | jmp next 52 | 53 | case_n: cmp al,0Ah ;newline : 10(0AH) 54 | jne case_c 55 | inc qword[ncount] 56 | jmp next 57 | 58 | case_c: cmp al,bl ;character 59 | jne next 60 | inc qword[ccount] 61 | 62 | next: inc rsi 63 | dec rcx ; 64 | jnz again ;loop again 65 | 66 | print smsg,smsg_len 67 | mov rax,[scount] 68 | call display 69 | 70 | print nmsg,nmsg_len 71 | mov rax,[ncount] 72 | call display 73 | 74 | print cmsg,cmsg_len 75 | mov rax,[ccount] 76 | call display 77 | 78 | fclose [filehandle] 79 | ret 80 | 81 | ;------------------------------------------------------------------ 82 | display: 83 | mov rsi,char_ans+3 ; load last byte address of char_ans in rsi 84 | mov rcx,4 ; number of digits 85 | 86 | cnt: mov rdx,0 ; make rdx=0 (as in div instruction rdx:rax/rbx) 87 | mov rbx,10 ; divisor=10 for decimal and 16 for hex 88 | div rbx 89 | ; cmp dl, 09h ; check for remainder in RDX 90 | ; jbe add30 91 | ; add dl, 07h 92 | ;add30: 93 | add dl,30h ; calculate ASCII code 94 | mov [rsi],dl ; store it in buffer 95 | dec rsi ; point to one byte back 96 | 97 | dec rcx ; decrement count 98 | jnz cnt ; if not zero repeat 99 | 100 | print char_ans,4 ; display result on screen 101 | ret 102 | ;---------------------------------------------------------------- 103 | 104 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/6C.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | int adj_mat[50][50] = {0}; 7 | int visited[50] = {0}; 8 | 9 | void dfs(int s, int n, string arr[]) 10 | { 11 | visited[s] = 1; 12 | cout << arr[s] << " "; 13 | for (int i = 0; i < n; i++) 14 | { 15 | if (adj_mat[s][i] && !visited[i]) 16 | dfs(i, n, arr); 17 | } 18 | } 19 | 20 | void bfs(int s, int n, string arr[]) 21 | { 22 | bool visited[n]; 23 | for (int i = 0; i < n; i++) 24 | visited[i] = false; 25 | 26 | int v; 27 | queue bfsq; 28 | 29 | if (!visited[s]) 30 | { 31 | cout << arr[s] << " "; 32 | bfsq.push(s); 33 | visited[s] = true; 34 | 35 | while (!bfsq.empty()) 36 | { 37 | v = bfsq.front(); 38 | for (int i = 0; i < n; i++) 39 | { 40 | if (adj_mat[v][i] && !visited[i]) 41 | { 42 | cout << arr[i] << " "; 43 | visited[i] = true; 44 | bfsq.push(i); 45 | } 46 | } 47 | bfsq.pop(); 48 | } 49 | } 50 | } 51 | 52 | int main() 53 | { 54 | cout << "Enter no. of cities: "; 55 | int n, u; 56 | cin >> n; 57 | string cities[n]; 58 | 59 | for (int i = 0; i < n; i++) 60 | { 61 | cout << "Enter city #" << i << " (Airport Code): "; 62 | cin >> cities[i]; 63 | } 64 | 65 | cout << "\nYour cities are: " << endl; 66 | for (int i = 0; i < n; i++) 67 | cout << "city #" << i << ": " << cities[i] << endl; 68 | 69 | for (int i = 0; i < n; i++) 70 | { 71 | for (int j = i + 1; j < n; j++) 72 | { 73 | cout << "Enter distance between " << cities[i] << " and " << cities[j] << ": "; 74 | cin >> adj_mat[i][j]; 75 | adj_mat[j][i] = adj_mat[i][j]; 76 | } 77 | } 78 | 79 | cout << endl; 80 | for (int i = 0; i < n; i++) 81 | cout << "\t" << cities[i] << "\t"; 82 | 83 | for (int i = 0; i < n; i++) 84 | { 85 | cout << "\n" 86 | << cities[i]; 87 | for (int j = 0; j < n; j++) 88 | cout << "\t" << adj_mat[i][j] << "\t"; 89 | cout << endl; 90 | } 91 | 92 | cout << "Enter Starting Vertex: "; 93 | cin >> u; 94 | 95 | cout << "DFS: "; 96 | dfs(u, n, cities); 97 | cout << endl; 98 | 99 | cout << "BFS: "; 100 | bfs(u, n, cities); 101 | 102 | return 0; 103 | } 104 | -------------------------------------------------------------------------------- /MPL/A1/A1.asm: -------------------------------------------------------------------------------- 1 | ;************************************************************* 2 | section .data 3 | 4 | nline db 10,10 5 | nline_len equ $-nline 6 | 7 | arr dd -11111111H, 22222222H, 33333333H, -44444444H, -55555555H 8 | arr_size equ 5 9 | 10 | pmsg db 10,"The no. of Positive elements in 32-bit array:" 11 | pmsg_len equ $-pmsg 12 | 13 | nmsg db 10,10,"The no. of Negative elements in 32-bit array:" 14 | nmsg_len equ $-nmsg 15 | 16 | ;************************************************************* 17 | section .bss 18 | 19 | p_count resq 01 20 | n_count resq 01 21 | dnumbuff resb 02 22 | 23 | %macro display 2 24 | mov rax,01 25 | mov rdi,01 26 | mov rsi,%1 27 | mov rdx,%2 28 | syscall 29 | %endmacro 30 | 31 | ;*********************************************************** 32 | 33 | section .text 34 | 35 | global _start 36 | 37 | _start: 38 | mov esi, arr 39 | mov ecx,5 ;Arraay counter i.e.5 40 | mov ebx,0 ; counter for +ve nos 41 | mov edx,0 ; counter for -ve nos 42 | 43 | next_num: 44 | mov eax,[esi] ; take no. in RAX 45 | rcl eax,1 ; rotate left 1 bit to check for sign bit 46 | jc negative 47 | 48 | positive: 49 | inc ebx ; no carry, so no. is +ve 50 | jmp next 51 | 52 | negative: 53 | inc edx ; carry, so no. is -ve 54 | 55 | next: 56 | add esi,4 ; 32 bit nos i.e. 4 bytes 57 | loop next_num 58 | 59 | mov [p_count], ebx ; store positive count 60 | mov [n_count], edx ; store negative count 61 | 62 | display pmsg, pmsg_len 63 | mov ebx,[p_count] ; load value of p_count in rax 64 | call disp8_proc ; display p_count 65 | 66 | display nmsg, nmsg_len 67 | mov ebx,[n_count] ; load value of n_count in rax 68 | call disp8_proc ; display n_count 69 | 70 | display nline, nline_len 71 | 72 | exit: 73 | mov rax,60 ;Exit 74 | mov rbx,00 75 | syscall 76 | 77 | 78 | 79 | 80 | ;********************************************************** 81 | disp8_proc: 82 | mov edi,dnumbuff ;point edi to buffer 83 | mov ecx,02 ;load number of digits to display 84 | 85 | dispup1: 86 | rol bl,4 ;rotate number left by four bits 87 | mov dl,bl ;move lower byte in dl 88 | and dl,0fh ;mask upper digit of byte in dl 89 | add dl,30h ;add 30h to calculate ASCII code 90 | cmp dl,39h ;compare with 39h 91 | jbe dispskip1 ;if less than 39h skip adding 07 more 92 | add dl,07h ;else add 07 93 | 94 | dispskip1: 95 | mov [edi],dl ;store ASCII code in buffer 96 | inc edi ;point to next byte 97 | loop dispup1 ;decrement the count of digits to display 98 | ;if not zero jump to repeat 99 | 100 | display dnumbuff,2 101 | ret 102 | 103 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/3A.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | struct node 8 | { 9 | char label[10]; 10 | int ch_count; 11 | struct node *child[10]; 12 | } *root; 13 | 14 | class GT 15 | { 16 | public: 17 | void create_tree(); 18 | void display(node *r1); 19 | GT() 20 | { 21 | root = NULL; 22 | } 23 | }; 24 | 25 | void GT::create_tree() 26 | { 27 | int tbooks, tchapters, i, j, k; 28 | root = new node; 29 | cout << "Enter name of book: "; 30 | cin >> root->label; 31 | cout << "Enter no. of chapters in book: "; 32 | cin >> tchapters; 33 | root->ch_count = tchapters; 34 | 35 | for (i = 0; i < tchapters; i++) 36 | { 37 | root->child[i] = new node; 38 | cout << "Enter Chapter name: "; 39 | cin >> root->child[i]->label; 40 | cout << "Enter no. of sections in Chapter " << root->child[i]->label << ": "; 41 | cin >> root->child[i]->ch_count; 42 | 43 | for (j = 0; j < root->child[i]->ch_count; j++) 44 | { 45 | root->child[i]->child[j] = new node; 46 | cout << "Enter Section " << j + 1 << " name: "; 47 | cin >> root->child[i]->child[j]->label; 48 | } 49 | } 50 | } 51 | 52 | void GT::display(node *r1) 53 | { 54 | int i, j, k, tchapters; 55 | if (r1 != NULL) 56 | { 57 | cout << "\n-----Book Hierarchy---"; 58 | cout << "\n Book title: " << r1->label; 59 | tchapters = r1->ch_count; 60 | 61 | for (i = 0; i < tchapters; i++) 62 | { 63 | cout << "\n Chapter " << i + 1; 64 | cout << " " << r1->child[i]->label; 65 | cout << "\n Sections"; 66 | 67 | for (j = 0; j < r1->child[i]->ch_count; j++) 68 | { 69 | cout << "\n " << r1->child[i]->child[j]->label; 70 | } 71 | } 72 | } 73 | } 74 | 75 | int main() 76 | { 77 | int choice; 78 | GT gt; 79 | 80 | while (1) 81 | { 82 | cout << "\nBook Tree Creation" << endl; 83 | cout << "\n1. Create" << endl; 84 | cout << "2. Display" << endl; 85 | cout << "3. Quit" << endl; 86 | cout << "Enter your choice: "; 87 | cin >> choice; 88 | 89 | switch (choice) 90 | { 91 | case 1: 92 | gt.create_tree(); 93 | break; 94 | case 2: 95 | gt.display(root); 96 | break; 97 | case 3: 98 | exit(1); 99 | default: 100 | cout << "Wrong choice" << endl; 101 | } 102 | } 103 | return 0; 104 | } 105 | -------------------------------------------------------------------------------- /MPL/A6/A6.asm: -------------------------------------------------------------------------------- 1 | section .data 2 | rmodemsg db 10,'Processor is in Real Mode' 3 | rmsg_len:equ $-rmodemsg 4 | 5 | pmodemsg db 10,'Processor is in Protected Mode' 6 | pmsg_len:equ $-pmodemsg 7 | 8 | gdtmsg db 10,'GDT Contents are::' 9 | gmsg_len:equ $-gdtmsg 10 | 11 | ldtmsg db 10,'LDT Contents are::' 12 | lmsg_len:equ $-ldtmsg 13 | 14 | idtmsg db 10,'IDT Contents are::' 15 | imsg_len:equ $-idtmsg 16 | 17 | trmsg db 10,'Task Register Contents are::' 18 | tmsg_len: equ $-trmsg 19 | 20 | mswmsg db 10,'Machine Status Word::' 21 | mmsg_len:equ $-mswmsg 22 | 23 | colmsg db ':' 24 | 25 | nwline db 10 26 | 27 | section .bss 28 | gdt resd 1 29 | resw 1 30 | ldt resw 1 31 | idt resd 1 32 | resw 1 33 | tr resw 1 34 | 35 | cr0_data resd 1 36 | 37 | dnum_buff resb 04 38 | 39 | %macro print 2 40 | mov rax,01 41 | mov rdi,01 42 | mov rsi,%1 43 | mov rdx,%2 44 | syscall 45 | %endmacro 46 | 47 | section .text 48 | global _start 49 | _start: 50 | smsw eax ;Reading CR0. As MSW is 32-bit cannot use RAX register. 51 | 52 | mov [cr0_data],rax 53 | 54 | bt rax,1 ;Checking PE bit, if 1=Protected Mode, else Real Mode 55 | jc prmode 56 | print rmodemsg,rmsg_len 57 | jmp nxt1 58 | 59 | prmode: print pmodemsg,pmsg_len 60 | 61 | nxt1: sgdt [gdt] 62 | sldt [ldt] 63 | sidt [idt] 64 | str [tr] 65 | print gdtmsg,gmsg_len 66 | 67 | mov bx,[gdt+4] 68 | call print_num 69 | 70 | mov bx,[gdt+2] 71 | call print_num 72 | 73 | print colmsg,1 74 | 75 | mov bx,[gdt] 76 | call print_num 77 | 78 | print ldtmsg,lmsg_len 79 | mov bx,[ldt] 80 | call print_num 81 | 82 | print idtmsg,imsg_len 83 | 84 | mov bx,[idt+4] 85 | call print_num 86 | 87 | mov bx,[idt+2] 88 | call print_num 89 | 90 | print colmsg,1 91 | 92 | mov bx,[idt] 93 | call print_num 94 | 95 | print trmsg,tmsg_len 96 | 97 | mov bx,[tr] 98 | call print_num 99 | 100 | print mswmsg,mmsg_len 101 | 102 | mov bx,[cr0_data+2] 103 | call print_num 104 | 105 | mov bx,[cr0_data] 106 | call print_num 107 | 108 | print nwline,1 109 | 110 | 111 | exit: mov rax,60 112 | xor rdi,rdi 113 | syscall 114 | 115 | print_num: 116 | mov rsi,dnum_buff ;point esi to buffer 117 | 118 | mov rcx,04 ;load number of digits to printlay 119 | 120 | up1: 121 | rol bx,4 ;rotate number left by four bits 122 | mov dl,bl ;move lower byte in dl 123 | and dl,0fh ;mask upper digit of byte in dl 124 | add dl,30h ;add 30h to calculate ASCII code 125 | cmp dl,39h ;compare with 39h 126 | jbe skip1 ;if less than 39h skip adding 07 more 127 | add dl,07h ;else add 07 128 | skip1: 129 | mov [rsi],dl ;store ASCII code in buffer 130 | inc rsi ;point to next byte 131 | loop up1 ;decrement the count of digits to printlay 132 | ;if not zero jump to repeat 133 | 134 | print dnum_buff,4 ;printlay the number from buffer 135 | 136 | ret 137 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/5B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | struct node 7 | { 8 | char data; 9 | node *left; 10 | node *right; 11 | }; 12 | 13 | class tree 14 | { 15 | char prefix[20]; 16 | 17 | public: 18 | node *top; 19 | 20 | void expression(char[]); 21 | void display(node *); 22 | void non_rec_postorder(node *); 23 | void del(node *); 24 | }; 25 | 26 | class stack1 27 | { 28 | node *data[30]; 29 | int top; 30 | 31 | public: 32 | stack1() 33 | { 34 | top = -1; 35 | } 36 | 37 | int empty() 38 | { 39 | if (top == -1) 40 | return 1; 41 | return 0; 42 | } 43 | 44 | void push(node *p) 45 | { 46 | data[++top] = p; 47 | } 48 | 49 | node *pop() 50 | { 51 | return (data[top--]); 52 | } 53 | }; 54 | 55 | void tree::expression(char prefix[]) 56 | { 57 | char c; 58 | stack1 s; 59 | node *t1, *t2; 60 | int len, i; 61 | 62 | len = strlen(prefix); 63 | 64 | for (i = len - 1; i >= 0; i--) 65 | { 66 | top = new node; 67 | top->left = NULL; 68 | top->right = NULL; 69 | 70 | if (isalpha(prefix[i])) 71 | { 72 | top->data = prefix[i]; 73 | s.push(top); 74 | } 75 | else if (prefix[i] == '+' || prefix[i] == '*' || prefix[i] == '-' || prefix[i] == '/') 76 | { 77 | t2 = s.pop(); 78 | t1 = s.pop(); 79 | top->data = prefix[i]; 80 | top->left = t2; 81 | top->right = t1; 82 | s.push(top); 83 | } 84 | } 85 | 86 | top = s.pop(); 87 | } 88 | 89 | void tree::display(node *root) 90 | { 91 | if (root != NULL) 92 | { 93 | cout << root->data; 94 | display(root->left); 95 | display(root->right); 96 | } 97 | } 98 | 99 | void tree::non_rec_postorder(node *top) 100 | { 101 | stack1 s1, s2; 102 | node *T = top; 103 | 104 | cout << "\n"; 105 | 106 | s1.push(T); 107 | 108 | while (!s1.empty()) 109 | { 110 | T = s1.pop(); 111 | s2.push(T); 112 | 113 | if (T->left != NULL) 114 | s1.push(T->left); 115 | 116 | if (T->right != NULL) 117 | s1.push(T->right); 118 | } 119 | 120 | while (!s2.empty()) 121 | { 122 | top = s2.pop(); 123 | cout << top->data; 124 | } 125 | } 126 | 127 | void tree::del(node *node) 128 | { 129 | if (node == NULL) 130 | return; 131 | 132 | del(node->left); 133 | del(node->right); 134 | 135 | cout << " Deleting node:" << node->data; 136 | free(node); 137 | } 138 | 139 | int main() 140 | { 141 | char expr[20]; 142 | tree t; 143 | 144 | cout << "Enter prefix Expression: "; 145 | cin >> expr; 146 | 147 | cout << "\nPrefix Expression\n"; 148 | cout << expr; 149 | 150 | t.expression(expr); 151 | return 0; 152 | } 153 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/10E.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | void MaxHeapify(int a[], int i, int n) 5 | { 6 | int j, temp; 7 | temp = a[i]; 8 | j = 2 * i; 9 | while (j <= n) 10 | { 11 | if (j < n && a[j + 1] > a[j]) 12 | j = j + 1; 13 | if (temp > a[j]) 14 | break; 15 | else if (temp <= a[j]) 16 | { 17 | a[j / 2] = a[j]; 18 | j = 2 * j; 19 | } 20 | } 21 | a[j / 2] = temp; 22 | } 23 | 24 | void MinHeapify(int a[], int i, int n) 25 | { 26 | int j, temp; 27 | temp = a[i]; 28 | j = 2 * i; 29 | while (j <= n) 30 | { 31 | if (j < n && a[j + 1] < a[j]) 32 | j = j + 1; 33 | if (temp < a[j]) 34 | break; 35 | else if (temp >= a[j]) 36 | { 37 | a[j / 2] = a[j]; 38 | j = 2 * j; 39 | } 40 | } 41 | a[j / 2] = temp; 42 | } 43 | 44 | void MaxHeapSort(int a[], int n) 45 | { 46 | int i, temp; 47 | for (i = n; i >= 2; i--) 48 | { 49 | temp = a[i]; 50 | a[i] = a[1]; 51 | a[1] = temp; 52 | MaxHeapify(a, 1, i - 1); 53 | } 54 | } 55 | 56 | void MinHeapSort(int a[], int n) 57 | { 58 | int i, temp; 59 | for (i = n; i >= 2; i--) 60 | { 61 | temp = a[i]; 62 | a[i] = a[1]; 63 | a[1] = temp; 64 | MinHeapify(a, 1, i - 1); 65 | } 66 | } 67 | 68 | void Build_MaxHeap(int a[], int n) 69 | { 70 | int i; 71 | for (i = n / 2; i >= 1; i--) 72 | MaxHeapify(a, i, n); 73 | } 74 | 75 | void Build_MinHeap(int a[], int n) 76 | { 77 | int i; 78 | for (i = n / 2; i >= 1; i--) 79 | MinHeapify(a, i, n); 80 | } 81 | 82 | int main() 83 | { 84 | int n, i; 85 | cout << "\nEnter number of subjects of second year: "; 86 | cin >> n; 87 | n++; 88 | int arr[n]; 89 | 90 | // Take input marks for all subjects 91 | for (i = 1; i < n; i++) 92 | { 93 | cout << "Enter the marks " << i << ": "; 94 | cin >> arr[i]; 95 | } 96 | 97 | Build_MaxHeap(arr, n - 1); // build maximum heap 98 | cout << "\nPrint array after building MaxHeap :: "; 99 | for (i = 1; i < n; i++) 100 | cout << " " << arr[i]; 101 | 102 | MaxHeapSort(arr, n - 1); // Apply max heap sort 103 | int max, min; 104 | cout << "\n\nSorted Data : ASCENDING : "; 105 | for (i = 1; i < n; i++) // Print the array 106 | cout << " " << arr[i]; 107 | min = arr[1]; 108 | 109 | Build_MinHeap(arr, n - 1); // build minimum heap 110 | cout << "\n\nPrint array after building MinHeap :: "; 111 | for (i = 1; i < n; i++) 112 | cout << " " << arr[i]; 113 | 114 | MinHeapSort(arr, n - 1); // apply min heap sort 115 | cout << "\n\nSorted Data : DESCENDING: "; 116 | max = arr[1]; 117 | for (i = 1; i < n; i++) // Print the array 118 | cout << " " << arr[i]; 119 | 120 | cout << "\n\nMaximum Marks : " << max << "\nMinimum marks : " << min; 121 | 122 | return 0; 123 | } 124 | -------------------------------------------------------------------------------- /MPL/A9/A9f.asm: -------------------------------------------------------------------------------- 1 | ;************************************************************** 2 | section .data 3 | nummsg db "***Program to find Factorial of a number*** ",10 4 | db "Enter the number : ", 5 | nummsg_len equ $-nummsg 6 | 7 | resmsg db "Factorial is : " 8 | resmsg_len equ $-resmsg 9 | 10 | thankmsg db 10,"Thank you ",10 11 | thankmsg_len equ $-thankmsg 12 | 13 | zerofact db " 00000001 " 14 | zerofactlen equ $-zerofact 15 | 16 | ;************************************************************ 17 | section .bss 18 | 19 | dispbuff resb 16 20 | result resb 4 21 | num resb 1 22 | num1 resb 1 23 | numascii resb 3 24 | 25 | %macro display 2 26 | mov rax,01 27 | mov rdi,01 28 | mov rsi,%1 29 | mov rdx,%2 30 | syscall 31 | %endmacro 32 | 33 | %macro accept 2 34 | mov rax,0 35 | mov rdi,0 36 | mov rsi,%1 37 | mov rdx,%2 38 | syscall 39 | %endmacro 40 | 41 | ;************************************************************ 42 | section .text 43 | 44 | global _start 45 | 46 | _start: 47 | 48 | display nummsg,nummsg_len 49 | accept numascii,3 ;accept number from user 50 | call packnum8_proc ;convert number from ascii to hex 51 | mov [num],bl 52 | 53 | 54 | 55 | display resmsg,resmsg_len 56 | 57 | mov al,[num] ;store number in accumulator 58 | cmp al,01h 59 | jbe endfact 60 | 61 | mov bl,[num] 62 | call proc_fact 63 | mov rbx,rax 64 | call disp64_proc 65 | jmp exit 66 | 67 | endfact: 68 | display zerofact,zerofactlen 69 | 70 | exit: 71 | display thankmsg,thankmsg_len 72 | 73 | mov rax,60 74 | mov rdi,0 75 | syscall 76 | ret 77 | 78 | ;************************************************************ 79 | disp64_proc: 80 | 81 | mov rdi,dispbuff ;point esi to buffer 82 | mov rcx,16 ;load number of digits to display 83 | 84 | dispup1: 85 | rol rbx,4 ;rotate number left by four bits 86 | mov dl,bl ;move lower byte in dl 87 | and dl,0fh ;mask upper digit of byte in dl 88 | add dl,30h ;add 30h to calculate ASCII code 89 | cmp dl,39h ;compare with 39h 90 | jbe dispskip1 ;if less than 39h akip adding 07 more 91 | add dl,07h ;else add 07 92 | 93 | dispskip1: 94 | mov [rdi],dl ;store ASCII code in buffer 95 | inc rdi ;point to next byte 96 | loop dispup1 ;decrement the count of digits to display 97 | ;if not zero jump to repeat 98 | 99 | display dispbuff,16 100 | ret 101 | ;************************************************************ 102 | packnum8_proc: 103 | 104 | mov bx,0 105 | mov ecx,02 106 | mov esi,numascii 107 | up1: 108 | rol bl,04 109 | mov al,[esi] 110 | cmp al,39h 111 | jbe skip1 112 | sub al,07h 113 | skip1: 114 | sub al,30h 115 | add bl,al 116 | inc esi 117 | loop up1 118 | ret 119 | ;***********************Recursion************************************* 120 | ;There are two kinds of recursion: direct and indirect. 121 | ;In direct recursion, the procedure calls itself and 122 | ;in indirect recursion, the first procedure calls a second 123 | ;procedure,which in turn, calls the first procedure. 124 | 125 | proc_fact: 126 | cmp bl, 1 127 | jne do_calculation 128 | mov ax, 1 129 | ret 130 | do_calculation: 131 | push rbx 132 | dec bl 133 | call proc_fact 134 | pop rbx 135 | mul bl 136 | ret 137 | ;**************************************** 138 | -------------------------------------------------------------------------------- /MPL/A2/A2-1.asm: -------------------------------------------------------------------------------- 1 | 2 | ;*************************************************************** 3 | section .data 4 | menumsg db 10,'---Menu for Non-overlapped Block Transfer---',10 5 | db 10,'1.Block Transfer without using string instructions' 6 | db 10,'2.Block Transfer with using string instructions' 7 | db 10,'3.Exit',10 8 | menumsg_len equ $-menumsg 9 | 10 | blk_bfrmsg db 10,'Block contents before transfer' 11 | blk_bfrmsg_len equ $-blk_bfrmsg 12 | 13 | blk_afrmsg db 10,'Block contents after transfer' 14 | blk_afrmsg_len equ $-blk_afrmsg 15 | 16 | srcmsg db 10,'Source block contents::' 17 | srcmsg_len equ $-srcmsg 18 | 19 | dstmsg db 10,'Destination block contents::' 20 | dstmsg_len equ $-dstmsg 21 | 22 | srcblk db 01h,02h,03h,04h,05h 23 | dstblk db 00,00,00,00,00 24 | 25 | spacechar db 20h 26 | spchlength equ $-spacechar 27 | 28 | ;****************.bss Section*************************** 29 | section .bss 30 | 31 | optionbuff resb 02 32 | dispbuff resb 02 33 | 34 | %macro display 2 35 | mov rax,01 36 | mov rdi,01 37 | mov rsi,%1 38 | mov rdx,%2 39 | syscall 40 | %endmacro 41 | 42 | %macro accept 2 43 | mov rax,00 44 | mov rdi,00 45 | mov rsi,%1 46 | mov rdx,%2 47 | syscall 48 | %endmacro 49 | 50 | ;*******************.text Section************************** 51 | 52 | section .text 53 | global _start 54 | _start: 55 | 56 | display blk_bfrmsg,blk_bfrmsg_len 57 | 58 | call dispsrc_blk_proc 59 | 60 | call dispdest_blk_proc 61 | menu: 62 | display menumsg,menumsg_len 63 | accept optionbuff,02 64 | cmp byte[optionbuff],31h 65 | je wos 66 | cmp byte[optionbuff],32h 67 | je ws 68 | 69 | exit: 70 | mov rax,60 ;Exit 71 | mov rbx,00 72 | syscall 73 | 74 | ;**************Display Source Block Procedure**************** 75 | dispsrc_blk_proc: 76 | 77 | display srcmsg,srcmsg_len 78 | mov rsi,srcblk 79 | mov rcx,05h 80 | up1: 81 | push rcx 82 | mov bl,[rsi] 83 | push rsi 84 | call disp8_proc 85 | display spacechar,spchlength 86 | 87 | pop rsi 88 | inc rsi 89 | pop rcx 90 | loop up1 91 | ret 92 | 93 | ;**************Display Destination Block Procedure************* 94 | dispdest_blk_proc: 95 | 96 | display dstmsg,dstmsg_len 97 | mov rdi,dstblk 98 | mov rcx,05 99 | up2: 100 | push rcx 101 | mov bl,[rdi] 102 | push rdi 103 | call disp8_proc 104 | display spacechar,spchlength 105 | pop rdi 106 | inc rdi 107 | pop rcx 108 | loop up2 109 | ret 110 | ;**************Without String Procedure************ 111 | wos: 112 | mov rsi,srcblk 113 | mov rdi,dstblk 114 | mov rcx,05 115 | 116 | again: 117 | mov bl,[rsi] 118 | mov [rdi],bl 119 | inc rsi 120 | inc rdi 121 | loop again 122 | display blk_afrmsg,blk_afrmsg_len 123 | call dispsrc_blk_proc 124 | call dispdest_blk_proc 125 | jmp menu 126 | ;************Using String Procedure**************** 127 | ws: 128 | mov rsi,srcblk 129 | mov rdi,dstblk 130 | mov rcx,05 131 | 132 | cld 133 | rep movsb 134 | display blk_afrmsg,blk_afrmsg_len 135 | call dispsrc_blk_proc 136 | call dispdest_blk_proc 137 | jmp menu 138 | ;************Display Procedure******************** 139 | disp8_proc: 140 | mov rsi,dispbuff 141 | mov rcx,02 142 | 143 | dup1: 144 | rol bl,4 145 | mov dl,bl 146 | and dl,0Fh 147 | cmp dl,09H 148 | jbe dskip 149 | add dl,07h 150 | 151 | dskip: 152 | add dl,30h 153 | mov [rsi],dl 154 | inc rsi 155 | loop dup1 156 | 157 | display dispbuff,02 158 | ret 159 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/2A.py: -------------------------------------------------------------------------------- 1 | class HashTable: 2 | def __init__(self): 3 | self.size = 10 4 | self.slots = [None] * self.size 5 | self.data = [None] * self.size 6 | self.indices = [-1] * self.size 7 | 8 | def insert(self, key, data): 9 | flag = 0 10 | hashvalue = self.hashfunction(key, len(self.slots)) 11 | same = hashvalue 12 | if self.slots[hashvalue] == None: 13 | self.slots[hashvalue] = key 14 | self.data[hashvalue] = data 15 | else: 16 | if self.slots[hashvalue] == key: 17 | self.data[hashvalue] = data # replace 18 | else: 19 | nextslot = self.nextloc(hashvalue, len(self.slots)) 20 | while self.slots[nextslot] != None and self.slots[nextslot] != key: 21 | nextslot = self.nextloc(nextslot, len(self.slots)) 22 | if self.slots[nextslot] == None: 23 | self.slots[nextslot] = key 24 | self.data[nextslot] = data 25 | self.indices[hashvalue] = nextslot 26 | else: 27 | self.data[nextslot] = data # replace 28 | 29 | def hashfunction(self, key, size): 30 | return key % size 31 | 32 | def nextloc(self, oldhash, size): 33 | return (oldhash + 1) % size 34 | 35 | def delete(self, key): 36 | hashvalue = self.hashfunction(key, len(self.slots)) 37 | flag = False 38 | check = 0 39 | while check != 1: 40 | if self.slots[hashvalue] == key: 41 | self.slots[hashvalue] = None 42 | self.data[hashvalue] = None 43 | self.indices[hashvalue] = -1 44 | check = 1 45 | flag = True 46 | break 47 | else: 48 | if self.indices[hashvalue] != -1: 49 | oldhash = hashvalue 50 | hashvalue = self.indices[hashvalue] 51 | self.indices[oldhash] = -1 52 | else: 53 | check = 1 54 | break 55 | 56 | def get(self, key): 57 | startslot = self.hashfunction(key, len(self.slots)) 58 | data = None 59 | stop = False 60 | found = False 61 | position = startslot 62 | while self.slots[position] != None and not found and not stop: 63 | if self.slots[position] == key: 64 | found = True 65 | data = self.data[position] 66 | else: 67 | position = self.nextloc(position, len(self.slots)) 68 | if position == startslot: 69 | stop = True 70 | return data 71 | 72 | def __getitem__(self, key): 73 | return self.get(key) 74 | 75 | def __setitem__(self, key, data): 76 | self.insert(key, data) 77 | 78 | 79 | H = HashTable() 80 | H[54] = "Rohit" 81 | H[26] = "Anaya" 82 | H[93] = "Nikita" 83 | H[17] = "Amar" 84 | H[77] = "Manali" 85 | H[31] = "Shilpa" 86 | H[44] = "Aniket" 87 | H[99] = "Prasad" 88 | H[20] = "Pawan" 89 | 90 | print("Keys:") 91 | print(H.slots) 92 | print("Data at their respective Keys:") 93 | print(H.data) 94 | print(H.indices) 95 | 96 | print(H[77]) 97 | H.delete(77) 98 | 99 | print("After deletion of data in H[77]") 100 | print("Keys:") 101 | print(H.slots) 102 | print("Data at their respective Keys:") 103 | print(H.data) 104 | print(H.indices) 105 | -------------------------------------------------------------------------------- /MPL/A3/A3.asm: -------------------------------------------------------------------------------- 1 | ;************************************************************ 2 | section .data 3 | 4 | menumsg db 10,10,'###### Menu for Code Conversion ######' 5 | db 10,'1: Hex to BCD' 6 | db 10,'2: BCD to Hex' 7 | db 10,'3: Exit' 8 | db 10,10,'Please Enter Choice::' 9 | menumsg_len equ $-menumsg 10 | 11 | hexinmsg db 10,10,'Please enter 4 digit hex number::' 12 | hexinmsg_len equ $-hexinmsg 13 | 14 | bcdopmsg db 10,10,'BCD Equivalent::' 15 | bcdopmsg_len equ $-bcdopmsg 16 | 17 | bcdinmsg db 10,10,'Please enter 5 digit BCD number::' 18 | bcdinmsg_len equ $-bcdinmsg 19 | 20 | hexopmsg db 10,10,'Hex Equivalent::' 21 | hexopmsg_len equ $-hexopmsg 22 | ;************************************************************ 23 | section .bss 24 | numascii resb 06 ;common buffer for choice, hex and bcd input 25 | outputbuff resb 02 26 | dispbuff resb 08 27 | 28 | %macro display 2 29 | mov rax,01 30 | mov rdi,01 31 | mov rsi,%1 32 | mov rdx,%2 33 | syscall 34 | %endmacro 35 | 36 | %macro accept 2 37 | mov rax,0 38 | mov rdi,0 39 | mov rsi,%1 40 | mov rdx,%2 41 | syscall 42 | %endmacro 43 | 44 | ;************************************************************ 45 | section .text 46 | 47 | global _start 48 | 49 | _start: 50 | 51 | menu: 52 | display menumsg,menumsg_len 53 | accept numascii,2 54 | 55 | cmp byte [numascii],'1' 56 | je hex2bcd_proc 57 | 58 | cmp byte [numascii],'2' 59 | je bcd2hex_proc 60 | 61 | cmp byte [numascii],'3' 62 | je exit 63 | jmp _start 64 | 65 | exit: 66 | mov rax,60 67 | mov rbx,0 68 | syscall 69 | ;************************************************************ 70 | hex2bcd_proc: 71 | display hexinmsg,hexinmsg_len 72 | accept numascii,5 73 | call packnum 74 | mov ax,bx 75 | mov rcx,0 76 | mov bx,10 ;Base of Decimal No. system 77 | h2bup1: 78 | mov dx,0 79 | div bx 80 | push rdx 81 | inc rcx 82 | cmp ax,0 83 | jne h2bup1 84 | mov rdi,outputbuff 85 | h2bup2: 86 | pop rdx 87 | add dl,30h 88 | mov [rdi],dl 89 | inc rdi 90 | loop h2bup2 91 | 92 | display bcdopmsg,bcdopmsg_len 93 | display outputbuff,5 94 | jmp menu 95 | 96 | ;************************************************************ 97 | bcd2hex_proc: 98 | display bcdinmsg,bcdinmsg_len 99 | accept numascii,6 100 | 101 | display hexopmsg,hexopmsg_len 102 | mov rsi,numascii 103 | mov rcx,05 104 | mov rax,0 105 | mov ebx,0ah 106 | b2hup1: 107 | mov rdx,0 108 | mul ebx 109 | mov dl,[rsi] 110 | sub dl,30h 111 | add rax,rdx 112 | inc rsi 113 | loop b2hup1 114 | mov ebx,eax 115 | call disp32_num 116 | jmp menu 117 | ;************************************************************ 118 | packnum: 119 | mov bx,0 120 | mov ecx,04 121 | mov esi,numascii 122 | up1: 123 | rol bx,04 124 | mov al,[esi] 125 | cmp al,39h 126 | jbe skip1 127 | sub al,07h 128 | skip1: 129 | sub al,30h 130 | add bl,al 131 | inc esi 132 | loop up1 133 | ret 134 | ;************************************************************ 135 | disp32_num: 136 | mov rdi,dispbuff ;point esi to buffer 137 | mov rcx,08 ;load number of digits to display 138 | dispup1: 139 | rol ebx,4 ;rotate number left by four bits 140 | mov dl,bl ;move lower byte in dl 141 | and dl,0fh ;mask upper digit of byte in dl 142 | add dl,30h ;add 30h to calculate ASCII code 143 | cmp dl,39h ;compare with 39h 144 | jbe dispskip1 ;if less than 39h akip adding 07 more 145 | add dl,07h ;else add 07 146 | dispskip1: 147 | mov [rdi],dl ;store ASCII code in buffer 148 | inc rdi ;point to next byte 149 | loop dispup1 ;decrement the count of digits to display 150 | ;if not zero jump to repeat 151 | 152 | display dispbuff+3,5 ;Dispays only lower 5 digits as upper three are '0' 153 | ret 154 | 155 | -------------------------------------------------------------------------------- /MPL/A2/A2-2.asm: -------------------------------------------------------------------------------- 1 | ;*********************************************************** 2 | section .data 3 | 4 | menumsg db 10,'##Menu for overlapped Block Transfer##',10 5 | db 10,'1.Block Overlap without using string instructions' 6 | db 10,'2.Block Overlap with using string instructions' 7 | db 10,'3.Exit',10,10 8 | menumsg_len equ $-menumsg 9 | 10 | blk_bfrmsg db 10,10,'Block contents before Overlap' 11 | blk_bfrmsg_len equ $-blk_bfrmsg 12 | 13 | blk_afrmsg db 10,'Block contents after Overlap',10 14 | blk_afrmsg_len equ $-blk_afrmsg 15 | 16 | srcmsg db 10,'Source block contents::' 17 | srcmsg_len equ $-srcmsg 18 | 19 | posmsg db 10,10,10,'Enter position to overlap::' 20 | posmsg_len equ $-posmsg 21 | 22 | spacechar db 20h 23 | spchlength equ $-spacechar 24 | 25 | srcblk db 01h,02h,03h,04h,05h,00h,00h,00h,00h,00h 26 | ;**********.bss Section********************** 27 | 28 | section .bss 29 | 30 | optionbuff resb 02 31 | dispbuff resb 02 32 | numascii resb 03 33 | 34 | pos resb 00 35 | 36 | %macro display 2 37 | mov rax,01 38 | mov rdi,01 39 | mov rsi,%1 40 | mov rdx,%2 41 | syscall 42 | %endmacro 43 | 44 | %macro accept 2 45 | mov rax,00 46 | mov rdi,00 47 | mov rsi,%1 48 | mov rdx,%2 49 | syscall 50 | %endmacro 51 | 52 | ;**********Text Section********************** 53 | section .text 54 | 55 | global _start 56 | 57 | _start: 58 | 59 | 60 | display blk_bfrmsg,blk_bfrmsg_len 61 | call disp_src_blk_proc 62 | 63 | display posmsg,posmsg_len 64 | accept numascii,3 65 | 66 | call packnum_proc 67 | 68 | menu: 69 | 70 | display menumsg,menumsg_len 71 | accept optionbuff,02 72 | 73 | cmp byte [optionbuff],31H 74 | je wos 75 | 76 | cmp byte [optionbuff],32H 77 | je ws 78 | 79 | exit: 80 | mov rax,60 81 | mov rbx,00 82 | syscall 83 | 84 | 85 | ;**********Display Block Procedure********************** 86 | 87 | 88 | disp_src_blk_proc: 89 | 90 | display srcmsg,srcmsg_len 91 | 92 | mov rsi,srcblk 93 | mov rcx,05h 94 | add cl,[pos] 95 | 96 | up1: 97 | 98 | push rcx 99 | mov bl,[rsi] 100 | push rsi 101 | call disp8_proc 102 | 103 | display spacechar,spchlength 104 | pop rsi 105 | inc rsi 106 | pop rcx 107 | loop up1 108 | ret 109 | 110 | ;************Without String Procedure*************** 111 | 112 | wos: 113 | 114 | mov rsi,srcblk+4 115 | 116 | mov rdi,rsi 117 | add rdi,[pos] 118 | mov rcx,05 119 | 120 | blkup1: 121 | 122 | mov al,[rsi] 123 | mov [rdi],al 124 | dec rsi 125 | dec rdi 126 | 127 | loop blkup1 128 | 129 | display blk_afrmsg,blk_afrmsg_len 130 | call disp_src_blk_proc 131 | jmp exit 132 | 133 | ;************Using String Procedure**************** 134 | 135 | ws: 136 | mov esi,srcblk+4 137 | mov edi,esi 138 | add edi,[pos] 139 | mov ecx,05 140 | 141 | std 142 | rep movsb 143 | 144 | display blk_afrmsg,blk_afrmsg_len 145 | call disp_src_blk_proc 146 | jmp exit 147 | 148 | 149 | ;************Display Procedure******************** 150 | 151 | disp8_proc: 152 | mov ecx,2 153 | 154 | mov edi,dispbuff 155 | 156 | dup1: 157 | 158 | rol bl,4 159 | mov dl,bl 160 | and dl,0fh 161 | cmp dl,09 162 | jbe dskip 163 | add dl,07h 164 | 165 | dskip: 166 | 167 | add dl,30h 168 | mov [edi],dl 169 | inc edi 170 | loop dup1 171 | 172 | display dispbuff,2 173 | ret 174 | 175 | 176 | ;************Packnum Procedure******************** 177 | packnum_proc: 178 | 179 | mov bx,0 180 | mov ecx,2 181 | mov esi,numascii 182 | 183 | up2: 184 | 185 | rol bl,4 186 | 187 | mov al,[esi] 188 | sub al,30h 189 | cmp al,09h 190 | jbe skip5 191 | sub al,07h 192 | 193 | 194 | skip5: 195 | 196 | add bl,al 197 | 198 | inc esi 199 | loop up2 200 | 201 | mov [pos],bl 202 | ret 203 | -------------------------------------------------------------------------------- /MPL/A7/A7.asm: -------------------------------------------------------------------------------- 1 | ;Assignment Name :X86/64 Assembly language program (ALP) 2 | ;To sort the list of integers in ascending/descending order using bubble sort. 3 | ;Read the input from the text file and write the sorted data back to the same text file. 4 | ;------------------------------------------------------------------------ 5 | 6 | %include "macro.asm" 7 | ;------------------------------------------------------------------------ 8 | section .data 9 | nline db 10 10 | nline_len equ $-nline 11 | 12 | ano db 10,10,10,10,"ML assignment 07 :- Bubble sort using file operations" 13 | db 10,"---------------------------------------------------",10 14 | ano_len equ $-ano 15 | 16 | filemsg db 10,"Enter filename of input data : " 17 | filemsg_len equ $-filemsg 18 | 19 | omsg db 10,"Sorting using bubble sort Operation successful." 20 | db 10,"Output stored in same file...",10,10 21 | omsg_len equ $-omsg 22 | 23 | errmsg db 10,"ERROR in opening/reading/writing File...",10 24 | errmsg_len equ $-errmsg 25 | 26 | ermsg db 10,"ERROR in writing File...",10 27 | ermsg_len equ $-ermsg 28 | 29 | exitmsg db 10,10,"Exit from program...",10,10 30 | exitmsg_len equ $-exitmsg 31 | 32 | ;--------------------------------------------------------------------------- 33 | section .bss 34 | buf resb 1024 35 | buf_len equ $-buf ; buffer length 36 | 37 | filename resb 50 38 | 39 | filehandle resq 1 40 | abuf_len resq 1 ; actual buffer length 41 | 42 | array resb 10 43 | n resq 1 44 | ;-------------------------------------------------------------------------- 45 | section .text 46 | global _start 47 | 48 | _start: 49 | print ano,ano_len ;assignment no. 50 | 51 | print filemsg,filemsg_len 52 | read filename,50 53 | dec rax 54 | mov byte[filename + rax],0 ; blank char/null char 55 | 56 | fopen filename ; on succes returns handle 57 | cmp rax,-1H ; on failure returns -1 58 | je Error 59 | mov [filehandle],rax 60 | 61 | fread [filehandle],buf, buf_len 62 | dec rax ; EOF 63 | mov [abuf_len],rax 64 | 65 | call bsort 66 | jmp Exit 67 | 68 | Error: print errmsg, errmsg_len 69 | 70 | Exit: print exitmsg,exitmsg_len 71 | exit 72 | ;-------------------------------------------------------------------------------- 73 | bsort: ; Bubble sort procedure 74 | call buf_array 75 | 76 | xor rax,rax 77 | mov rbp,[n] 78 | dec rbp 79 | 80 | xor rcx,rcx 81 | xor rdx,rdx 82 | xor rsi,rsi 83 | xor rdi,rdi 84 | 85 | mov rcx,0 ; i=0 86 | 87 | oloop: mov rbx,0 ; j=0 88 | 89 | mov rsi,array ; a[j] 90 | 91 | iloop: mov rdi,rsi ; a[j+1] 92 | inc rdi 93 | 94 | mov al,[rsi] 95 | cmp al,[rdi] 96 | jbe next 97 | 98 | mov dl,0 99 | mov dl,[rdi] ; swap 100 | mov [rdi],al 101 | mov [rsi],dl 102 | 103 | next: inc rsi 104 | inc rbx ; j++ 105 | cmp rbx,rbp 106 | jb iloop 107 | 108 | inc rcx 109 | cmp rcx,rbp 110 | jb oloop 111 | 112 | fwrite [filehandle],omsg, omsg_len 113 | fwrite [filehandle],array,[n] 114 | 115 | fclose [filehandle] 116 | 117 | print omsg, omsg_len 118 | print array,[n] 119 | 120 | RET 121 | 122 | Error1: 123 | print ermsg, ermsg_len 124 | RET 125 | ;------------------------------------------------------------------ 126 | buf_array: 127 | xor rcx,rcx 128 | xor rsi,rsi 129 | xor rdi,rdi 130 | 131 | mov rcx,[abuf_len] 132 | mov rsi,buf 133 | mov rdi,array 134 | 135 | next_num: 136 | mov al,[rsi] 137 | mov [rdi],al 138 | 139 | inc rsi ; number 140 | inc rsi ; newline 141 | inc rdi 142 | 143 | inc byte[n] ; counter 144 | 145 | dec rcx ; number 146 | dec rcx ; newline 147 | jnz next_num 148 | ret 149 | ;------------------------------------------------------------------ 150 | -------------------------------------------------------------------------------- /MPL/A10/A10.asm: -------------------------------------------------------------------------------- 1 | ;Like printf function in c's asm code 2 | 3 | %macro myprintf 1 4 | mov rdi,formatpf 5 | sub rsp,8 6 | movsd xmm0,[%1] 7 | mov rax,1 8 | call printf 9 | add rsp,8 10 | ;syscall 11 | %endmacro 12 | 13 | ;--- scanff function 14 | 15 | %macro myscanf 1 16 | mov rdi,formatsf 17 | mov rax,0 18 | mov rsi,%1 19 | call scanf 20 | ;syscall 21 | %endmacro 22 | 23 | ;----- Normal System call macro ---- 24 | 25 | %macro scall 4 26 | mov rax,%1 27 | mov rdi,%2 28 | mov rsi,%3 29 | mov rdx,%4 30 | syscall 31 | %endmacro 32 | 33 | ;------ Data Section ------ 34 | 35 | Section .data 36 | 37 | ff1: db "%lf +i %lf",10,0 ;format for printf/scanf argument printing 38 | ff2: db "%lf -i %lf",10,0 ;formatpi: db "%d",10,0 39 | formatpf: db "%lf",10,0 40 | formatsf: db "%lf",0 41 | four: dq 4 ; 4 for using in formula 42 | two: dq 2 43 | ;ipart1: db " +i ", 10 44 | ;ipart2: db " -i " , 10 45 | rmsg: db 0x0A,"Roots are real. Roots: ",0x0A 46 | rmsg_len: equ $-rmsg 47 | imsg: db "Roots are complex. Roots ",0x0A 48 | imsg_len: equ $-imsg 49 | title: db "====== QUadratic Equations ========",0x0A 50 | db "Enter a ,b,c : ",0x0A 51 | title_len: equ $-title 52 | 53 | ;------ BSS Section ----- 54 | 55 | section .bss 56 | 57 | a: resq 1 58 | b: resq 1 59 | c: resq 1 60 | b2: resq 1 ; b square 61 | fac: resq 1 ; 4ac 62 | delta: resq 1 ; delta value 63 | rdelta: resq 1 ; root of delta 64 | r1: resq 1 ;root 1 65 | r2: resq 1 ;root 2 66 | ta: resq 1 ; 2a 67 | realn: resq 1 68 | img1: resq 1 69 | ;img2 : resq 1 70 | 71 | ;---------------------- 72 | 73 | Section .text 74 | 75 | extern printf 76 | extern scanf 77 | 78 | global main: 79 | main: 80 | 81 | scall 1,1, title,title_len 82 | ;;-------- Scanning numbers 83 | 84 | myscanf a 85 | myscanf b 86 | myscanf c 87 | 88 | ;;======== Printing values for checking 89 | 90 | ;myprintf a 91 | ;myprintf b 92 | ;myprintf c 93 | 94 | ;==== Calculating b square 95 | 96 | fld qword[b] 97 | fmul qword[b] 98 | fstp qword[b2] 99 | 100 | ;------- Calculating 4ac 101 | 102 | fild qword[four] 103 | fmul qword[a] 104 | fmul qword[c] 105 | fstp qword[fac] 106 | 107 | ; calculating delta 108 | 109 | fld qword[b2] 110 | fsub qword[fac] 111 | fstp qword[delta] 112 | 113 | ;calcualating 2a 114 | 115 | fild qword[two] 116 | fmul qword[a] 117 | fstp qword[ta] 118 | 119 | btr qword[delta],63 120 | ;bit test set carry if flag is set else reset it 121 | jc IMAGINARY 122 | 123 | scall 1,1,rmsg, rmsg_len 124 | ;;--------------- REAL ROOTS -------- 125 | fld qword[delta] 126 | fsqrt 127 | fstp qword[rdelta] 128 | 129 | ;----- (-b+squareroot(delta))/2a 130 | 131 | fldz 132 | fsub qword[b] 133 | fadd qword[rdelta] 134 | fdiv qword[ta] 135 | fstp qword[r1] 136 | myprintf r1 137 | 138 | ;----- (-b-squareroot(delta))/2a 139 | 140 | fldz 141 | fsub qword[b] 142 | fsub qword[rdelta] 143 | fdiv qword[ta] 144 | fstp qword[r2] 145 | myprintf r2 146 | 147 | jmp EXIT 148 | 149 | IMAGINARY: 150 | scall 1,1, imsg,imsg_len 151 | 152 | fld qword[delta] 153 | fsqrt 154 | fstp qword[rdelta] 155 | 156 | ;real part of root 157 | fldz 158 | fsub qword[b] 159 | fdiv qword[ta] 160 | fstp qword[realn] 161 | 162 | fld qword[rdelta] 163 | fdiv qword[ta] 164 | fstp qword[img1] 165 | 166 | ;---- printing imag roots 167 | mov rdi,ff1 168 | sub rsp,8 169 | movsd xmm0,[realn] 170 | movsd xmm1,[img1] 171 | mov rax,2 172 | call printf 173 | add rsp,8 174 | 175 | mov rdi,ff2 176 | sub rsp,8 177 | movsd xmm0, [realn] 178 | movsd xmm1, [img1] 179 | mov rax,2 180 | call printf 181 | add rsp,8 182 | 183 | jmp EXIT 184 | 185 | EXIT: 186 | mov rax,60 187 | mov rdi,0 188 | syscall 189 | 190 | 191 | ;vivek@vivek-gouda-pc:~/Desktop/Microprocessor Lab/Assignment 10$ nasm -f elf64 quadratic.asm 192 | ;vivek@vivek-gouda-pc:~/Desktop/Microprocessor Lab/Assignment 10$ gcc -o quadratic quadratic.o 193 | ;vivek@vivek-gouda-pc:~/Desktop/Microprocessor Lab/Assignment 10$ ./quadratic 194 | ;====== QUadratic Equations ======== 195 | ;Enter a ,b,c : 196 | ;1 197 | ;0 198 | ;-16 199 | 200 | ;Roots are real. Roots: 201 | ;4.000000 202 | ;-4.000000 203 | ;vivek@vivek-gouda-pc:~/Desktop/Microprocessor Lab/Assignment 10$ 204 | 205 | -------------------------------------------------------------------------------- /MPL/A12/A12.asm: -------------------------------------------------------------------------------- 1 | ;Write 387 program to print mean, variance, standard deviation. 2 | 3 | ;-------------------------------------------------------------------------- 4 | %macro print 2 5 | mov rax,01 6 | mov rdi,01 7 | mov rsi,%1 8 | mov rdx,%2 9 | syscall 10 | %endmacro 11 | 12 | ;-------------------------------------------------------------------------- 13 | section .data 14 | m0 db 10,"Program to calculate mean, variance, standard deviation:" 15 | l0:equ $-m0 16 | 17 | m1 db 10,"Mean is" 18 | l1:equ $-m1 19 | 20 | m2 db 10,"Variance is" 21 | l2:equ $-m2 22 | 23 | m3 db 10,"Standard Deviation is" 24 | l3:equ $-m3 25 | 26 | m4 db 10,"Values are: 102.59, 198.21, 100.67" 27 | l4:equ $-m4 28 | 29 | dpoint db "." 30 | 31 | hdec dq 100 32 | 33 | num1 dd 102.59 34 | num2 dd 198.21 35 | num3 dd 100.67 36 | num4 dd 3.00 37 | 38 | newline db 0xa 39 | 40 | ;-------------------------------------------------------------------------- 41 | section .bss 42 | 43 | dispbuff resb 1 44 | resbuff resb 10 ;or we can also write resbuff rest 1 45 | mean resd 1 46 | variance resd 1 47 | 48 | ;-------------------------------------------------------------------------- 49 | section .text 50 | 51 | global _start 52 | _start: 53 | print m0,l0 54 | print m4,l4 55 | 56 | finit ;initialize coprocessor 57 | fldz ;load stack top 0 58 | 59 | ;logic to calculate mean 60 | 61 | fld dword[num1] ;first number on x387 62 | fld dword[num2] 63 | 64 | fadd st0,st1 65 | 66 | fld dword[num3] 67 | fadd st0,st1 68 | 69 | fdiv dword[num4] ;st0=add/3=mean 70 | fst dword[mean] 71 | 72 | print m1,l1 73 | 74 | call disp_result 75 | 76 | print newline,01 ;newline 77 | 78 | 79 | 80 | ;logic to calculate variance 81 | 82 | mov rsi,num1 83 | call cal_diff_sqr 84 | 85 | mov rsi,num2 86 | call cal_diff_sqr 87 | 88 | fadd st0,st1 89 | 90 | mov rsi,num3 91 | call cal_diff_sqr 92 | 93 | fadd st0,st1 94 | 95 | fdiv dword[num4] ;divide by cardinality 96 | 97 | fst dword[variance] 98 | 99 | print m2,l2 100 | 101 | call disp_result 102 | 103 | print newline,01 ;newline 104 | 105 | ;logic to calculate standard deviation 106 | 107 | fld dword[variance] 108 | fsqrt 109 | 110 | print m3,l3 111 | call disp_result 112 | 113 | print newline,01 ;newline 114 | 115 | mov rax,60 116 | mov rdi,0 117 | syscall 118 | 119 | ;-------------------------------------------------------------------------- 120 | disp_result: 121 | fimul dword[hdec] 122 | fbstp [resbuff] ;store bcd and pop from top of the stack 123 | 124 | xor rcx,rcx ;clear rcx register 125 | mov rcx,09h 126 | mov rsi,resbuff+9 ;rsi pointing to msb of resultant 127 | 128 | up1: 129 | push rcx 130 | push rsi 131 | 132 | mov bl,[rsi] 133 | call disp8_proc 134 | 135 | print dispbuff,02 136 | pop rsi 137 | dec rsi 138 | pop rcx 139 | loop up1 140 | 141 | print dpoint,01 142 | 143 | mov bl,[resbuff] 144 | call disp8_proc 145 | 146 | print dispbuff,02 147 | 148 | ret 149 | 150 | ;-------------------------------------------------------------------------- 151 | disp8_proc: 152 | mov rdi,dispbuff 153 | mov rcx,02 154 | 155 | back: 156 | rol bl,04 157 | mov dl,bl 158 | and dl,0Fh 159 | cmp dl,09h 160 | jbe skip 161 | add dl,07h 162 | 163 | skip: 164 | add dl,30h 165 | mov [rdi],dl 166 | inc rdi 167 | loop back 168 | ret 169 | 170 | cal_diff_sqr: 171 | fld dword[rsi] 172 | fsub dword[mean] 173 | fmul st0,st0 174 | ret 175 | ;-------------------------------------------------------------------------- 176 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/8D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | #define SIZE 10 4 | 5 | class OBST 6 | { 7 | int p[SIZE]; // Probabilities with which we search for an element 8 | int q[SIZE]; // Probabilities that an element is not found 9 | int a[SIZE]; // Elements from which OBST is to be built 10 | int w[SIZE][SIZE]; // Weight 'w[i][j]' of a tree having root 'r[i][j]' 11 | int c[SIZE][SIZE]; // Cost 'c[i][j]' of a tree having root 'r[i][j] 12 | int r[SIZE][SIZE]; // Represents root 13 | int n; // number of nodes 14 | 15 | public: 16 | /* This function accepts the input data */ 17 | void get_data() 18 | { 19 | int i; 20 | cout << "\n Optimal Binary Search Tree \n"; 21 | cout << "\n Enter the number of nodes: "; 22 | cin >> n; 23 | cout << "\n Enter the data as...\n"; 24 | for (i = 1; i <= n; i++) 25 | { 26 | cout << "\n a[" << i << "]: "; 27 | cin >> a[i]; 28 | } 29 | for (i = 1; i <= n; i++) 30 | { 31 | cout << "\n p[" << i << "]: "; 32 | cin >> p[i]; 33 | } 34 | for (i = 0; i <= n; i++) 35 | { 36 | cout << "\n q[" << i << "]: "; 37 | cin >> q[i]; 38 | } 39 | } 40 | 41 | /* This function returns a value in the range 'r[i][j-1]' to 'r[i+1][j]' so that the cost 'c[i][k-1]+c[k][j]' is minimum */ 42 | int Min_Value(int i, int j) 43 | { 44 | int m, k; 45 | int minimum = 32000; 46 | for (m = r[i][j - 1]; m <= r[i + 1][j]; m++) 47 | { 48 | if ((c[i][m - 1] + c[m][j]) < minimum) 49 | { 50 | minimum = c[i][m - 1] + c[m][j]; 51 | k = m; 52 | } 53 | } 54 | return k; 55 | } 56 | 57 | /* This function builds the table from all the given probabilities. It basically computes C, r, W values */ 58 | void build_OBST() 59 | { 60 | int i, j, k, m; 61 | for (i = 0; i < n; i++) 62 | { 63 | w[i][i] = q[i]; 64 | r[i][i] = c[i][i] = 0; 65 | w[i][i + 1] = q[i] + q[i + 1] + p[i + 1]; 66 | r[i][i + 1] = i + 1; 67 | c[i][i + 1] = q[i] + q[i + 1] + p[i + 1]; 68 | } 69 | w[n][n] = q[n]; 70 | r[n][n] = c[n][n] = 0; 71 | for (m = 2; m <= n; m++) 72 | { 73 | for (i = 0; i <= n - m; i++) 74 | { 75 | j = i + m; 76 | w[i][j] = w[i][j - 1] + p[j] + q[j]; 77 | k = Min_Value(i, j); 78 | c[i][j] = w[i][j] + c[i][k - 1] + c[k][j]; 79 | r[i][j] = k; 80 | } 81 | } 82 | } 83 | 84 | void build_tree() 85 | { 86 | int i, j, k; 87 | int queue[20], front = -1, rear = -1; 88 | cout << "The Optimal Binary Search Tree For the Given Node Is...\n"; 89 | cout << "\n The Root of this OBST is: " << r[0][n]; 90 | cout << "\nThe Cost of this OBST is: " << c[0][n]; 91 | cout << "\n\n\t NODE \t LEFT CHILD \t RIGHT CHILD "; 92 | cout << "\n"; 93 | queue[++rear] = 0; 94 | queue[++rear] = n; 95 | while (front != rear) 96 | { 97 | i = queue[++front]; 98 | j = queue[++front]; 99 | k = r[i][j]; 100 | cout << "\n\t" << k; 101 | if (r[i][k - 1] != 0) 102 | { 103 | cout << "\t\t" << r[i][k - 1]; 104 | queue[++rear] = i; 105 | queue[++rear] = k - 1; 106 | } 107 | else 108 | { 109 | cout << "\t\t"; 110 | } 111 | if (r[k][j] != 0) 112 | { 113 | cout << "\t" << r[k][j]; 114 | queue[++rear] = k; 115 | queue[++rear] = j; 116 | } 117 | else 118 | { 119 | cout << "\t"; 120 | } 121 | } 122 | cout << "\n"; 123 | } 124 | }; 125 | 126 | int main() 127 | { 128 | OBST obj; 129 | obj.get_data(); 130 | obj.build_OBST(); 131 | obj.build_tree(); 132 | return 0; 133 | } 134 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/README.md: -------------------------------------------------------------------------------- 1 | # List of Practicals 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 17 | 18 | 19 | 20 | 21 | 22 | 26 | 27 | 28 | 29 | 30 | 31 | 34 | 35 | 36 | 37 | 38 | 39 | 47 | 48 | 49 | 50 | 51 | 52 | 54 | 55 | 56 | 57 | 58 | 59 | 65 | 66 | 67 | 68 | 69 | 70 | 74 | 75 | 76 | 77 | 78 | 79 | 82 | 83 | 84 | 85 | 86 | 87 | 92 | 93 | 94 | 95 | 96 | 97 | 100 | 101 | 102 | 103 | 104 | 105 | 109 | 110 | 111 | 112 | 113 | 117 | 118 | 119 | 120 |
Sr. No.GroupTitile of Assignment
1AConsider a telephone book database of N clients. Make use of a hash table implementation 14 | to quickly look up client‘s telephone number. Make use of two collision handling 15 | techniques and compare them using number of comparisons required to find a set of 16 | telephone numbers (Python)
2AImplement all the functions of a dictionary (ADT) using hashing and handle collisions 23 | using chaining with / without replacement.
24 | Data: Set of (key, value) pairs, Keys are mapped to values, Keys must be comparable, Keys 25 | must be unique Standard Operations: Insert(key, value), Find(key), Delete(key) (python)
3AA book consists of chapters, chapters consist of sections and sections consist of 32 | subsections. Construct a tree and print the nodes. Find the time and space requirements 33 | of your method.
4BBeginning with an empty binary search tree, Construct binary search tree by inserting the 40 | values in the order given. After constructing a binary tree -
41 | i. Insert new node
42 | ii. Find number of nodes in longest path from root
43 | iii. Minimum data value found in the tree
44 | iv. Change a tree so that the roles of the left and right pointers are swapped at every 45 | node
46 | v. Search a value
5BConstruct an expression tree from the given prefix expression eg. +--a*bc/def and 53 | traverse it using postorder traversal(non recursive) and then delete the entire tree.
6CThere are flight paths between cities. If there is a flight between city A and city B then 60 | there is an edge between the cities. The cost of the edge can be the time that flight take 61 | to reach city B from A, or the amount of fuel used for the journey. Represent this as a 62 | graph. The node can be represented by airport name or name of the city. Use adjacency 63 | list representation of the graph or use adjacency matrix representation of the graph. 64 | Check whether the graph is connected or not. Justify the storage representation used.
7CYou have a business with several offices; you want to lease phone lines to connect them 71 | up with each other; and the phone company charges different amounts of money to 72 | connect different pairs of cities. You want a set of lines that connects all your offices with 73 | a minimum total cost. Solve the problem by suggesting appropriate data structures.
8DGiven sequence k = k1 <k2 < ... <kn of n sorted keys, with a search probability pi for each 80 | key ki . Build the Binary search tree that has the least search cost given the access 81 | probability for each key?
9DA Dictionary stores keywords & its meanings. Provide facility for adding new keywords, 88 | deleting keywords, updating values of any entry. Provide facility to display whole data 89 | sorted in ascending/ Descending order. Also find how many maximum comparisons may 90 | require for finding any keyword. Use Height balance tree and find the complexity for 91 | finding a keyword.
10ERead the marks obtained by students of second year in an online examination of particular 98 | subject. Find out maximum and minimum marks obtained in that subject. Use heap data 99 | structure. Analyze the algorithm.
11FDepartment maintains a student information. The file contains roll number, name, division and 106 | address. Allow user to add, delete information of student. Display information of particular 107 | employee. If record of student does not exist an appropriate message is displayed.If it is, then 108 | the system displays the student details. Use sequential file to maintain the data.
12FCompany maintains employee information as employee ID, name, designation and salary. 114 | Allow user to add, delete information of employee. Display information of particular 115 | employee. If employee does not exist an appropriate message is displayed. If it is, then the 116 | system displays the employee details. Use index sequential file to maintain the data.
121 | 122 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/12F.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | using namespace std; 5 | 6 | class Employee 7 | { 8 | private: 9 | int code; 10 | char name[20]; 11 | float salary; 12 | 13 | public: 14 | void read(); 15 | void display(); 16 | int getEmpCode() { return code; } 17 | int getSalary() { return salary; } 18 | void updateSalary(float s) { salary = s; } 19 | }; 20 | 21 | fstream file; 22 | 23 | void deleteExistingFile() 24 | { 25 | remove("EMPLOYEE.DAT"); 26 | } 27 | 28 | void appendToFile() 29 | { 30 | Employee x; 31 | x.read(); 32 | file.open("EMPLOYEE.DAT", ios::binary | ios::app); 33 | if (!file) 34 | { 35 | cout << "ERROR IN CREATING FILE\n"; 36 | return; 37 | } 38 | file.write(reinterpret_cast(&x), sizeof(x)); 39 | file.close(); 40 | cout << "Record added successfully.\n"; 41 | } 42 | 43 | void displayAll() 44 | { 45 | Employee x; 46 | file.open("EMPLOYEE.DAT", ios::binary | ios::in); 47 | if (!file) 48 | { 49 | cout << "ERROR IN OPENING FILE\n"; 50 | return; 51 | } 52 | while (file.read(reinterpret_cast(&x), sizeof(x))) 53 | { 54 | if (x.getSalary() >= 10000 && x.getSalary() <= 20000) 55 | { 56 | x.display(); 57 | } 58 | } 59 | file.close(); 60 | } 61 | 62 | void searchForRecord() 63 | { 64 | Employee x; 65 | int c; 66 | int isFound = 0; 67 | cout << "Enter employee code: "; 68 | cin >> c; 69 | file.open("EMPLOYEE.DAT", ios::binary | ios::in); 70 | if (!file) 71 | { 72 | cout << "ERROR IN OPENING FILE\n"; 73 | return; 74 | } 75 | while (file.read(reinterpret_cast(&x), sizeof(x))) 76 | { 77 | if (x.getEmpCode() == c) 78 | { 79 | cout << "RECORD FOUND\n"; 80 | x.display(); 81 | isFound = 1; 82 | break; 83 | } 84 | } 85 | if (isFound == 0) 86 | { 87 | cout << "Record not found!!!\n"; 88 | } 89 | file.close(); 90 | } 91 | 92 | void increaseSalary() 93 | { 94 | Employee x; 95 | int c; 96 | int isFound = 0; 97 | float sal; 98 | cout << "Enter employee code: "; 99 | cin >> c; 100 | file.open("EMPLOYEE.DAT", ios::binary | ios::in); 101 | if (!file) 102 | { 103 | cout << "ERROR IN OPENING FILE\n"; 104 | return; 105 | } 106 | while (file.read(reinterpret_cast(&x), sizeof(x))) 107 | { 108 | if (x.getEmpCode() == c) 109 | { 110 | cout << "Salary hike? "; 111 | cin >> sal; 112 | x.updateSalary(x.getSalary() + sal); 113 | isFound = 1; 114 | break; 115 | } 116 | } 117 | if (isFound == 0) 118 | { 119 | cout << "Record not found!!!\n"; 120 | } 121 | file.close(); 122 | cout << "Salary updated successfully." << endl; 123 | } 124 | 125 | void insertRecord() 126 | { 127 | Employee x, newEmp; 128 | newEmp.read(); 129 | fstream fin; 130 | file.open("EMPLOYEE.DAT", ios::binary | ios::in); 131 | fin.open("TEMP.DAT", ios::binary | ios::out); 132 | if (!file) 133 | { 134 | cout << "Error in opening EMPLOYEE.DAT file!!!\n"; 135 | return; 136 | } 137 | if (!fin) 138 | { 139 | cout << "Error in opening TEMP.DAT file!!!\n"; 140 | return; 141 | } 142 | while (file.read(reinterpret_cast(&x), sizeof(x))) 143 | { 144 | if (x.getEmpCode() > newEmp.getEmpCode()) 145 | { 146 | fin.write(reinterpret_cast(&newEmp), sizeof(newEmp)); 147 | newEmp = x; 148 | } 149 | else 150 | { 151 | fin.write(reinterpret_cast(&x), sizeof(x)); 152 | } 153 | } 154 | fin.write(reinterpret_cast(&newEmp), sizeof(newEmp)); 155 | fin.close(); 156 | file.close(); 157 | rename("TEMP.DAT", "EMPLOYEE.DAT"); 158 | remove("TEMP.DAT"); 159 | cout << "Record inserted successfully." << endl; 160 | } 161 | 162 | void Employee::read() 163 | { 164 | cout << "Enter employee code: "; 165 | cin >> code; 166 | cout << "Enter name: "; 167 | cin.ignore(1); 168 | cin.getline(name, 20); 169 | cout << "Enter salary: "; 170 | cin >> salary; 171 | } 172 | 173 | void Employee::display() 174 | { 175 | cout << code << " " << name << "\t" << salary << endl; 176 | } 177 | 178 | int main() 179 | { 180 | char ch; 181 | deleteExistingFile(); 182 | do 183 | { 184 | int n; 185 | cout << "ENTER CHOICE\n" 186 | << "1. ADD AN EMPLOYEE\n" 187 | << "2. DISPLAY\n" 188 | << "3. SEARCH\n" 189 | << "4. INCREASE SALARY\n" 190 | << "5. INSERT RECORD\n"; 191 | cout << "Make a choice: "; 192 | cin >> n; 193 | switch (n) 194 | { 195 | case 1: 196 | appendToFile(); 197 | break; 198 | case 2: 199 | displayAll(); 200 | break; 201 | case 3: 202 | searchForRecord(); 203 | break; 204 | case 4: 205 | increaseSalary(); 206 | break; 207 | case 5: 208 | insertRecord(); 209 | break; 210 | default: 211 | cout << "Invalid Choice\n"; 212 | } 213 | cout << "Do you want to continue? (Y/N): "; 214 | cin >> ch; 215 | } while (ch == 'Y' || ch == 'y'); 216 | return 0; 217 | } 218 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/4B.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | using namespace std; 3 | 4 | class bstnode 5 | { 6 | int data; 7 | bstnode *right; 8 | bstnode *left; 9 | 10 | public: 11 | bstnode *create(int data); 12 | bstnode *insert(bstnode *root, int data); 13 | bool search(bstnode *root, int data); 14 | void preorder(bstnode *root); 15 | void inorder(bstnode *root); 16 | void postorder(bstnode *root); 17 | int min(bstnode *root); 18 | int height(bstnode *root); 19 | void mirror(bstnode *root); 20 | }; 21 | 22 | bstnode *bstnode::create(int data) 23 | { 24 | bstnode *temp; 25 | temp = new bstnode(); 26 | temp->data = data; 27 | temp->left = temp->right = NULL; 28 | return temp; 29 | } 30 | 31 | bstnode *bstnode::insert(bstnode *root, int data) 32 | { 33 | if (root == NULL) 34 | { 35 | root = create(data); 36 | cout << "\n" 37 | << root->data << "\n"; 38 | } 39 | else if (data < root->data) 40 | { 41 | root->left = insert(root->left, data); 42 | cout << root->left->data << "->"; 43 | } 44 | else if (data > root->data) 45 | { 46 | root->right = insert(root->right, data); 47 | cout << root->right->data << "->"; 48 | } 49 | return root; 50 | } 51 | 52 | bool bstnode::search(bstnode *root, int data) 53 | { 54 | if (root == NULL) 55 | { 56 | return false; 57 | } 58 | else if (root->data == data) 59 | { 60 | return true; 61 | } 62 | else if (data < root->data) 63 | { 64 | return search(root->left, data); 65 | } 66 | else if (data > root->data) 67 | { 68 | return search(root->right, data); 69 | } 70 | } 71 | 72 | void bstnode::preorder(bstnode *root) 73 | { 74 | if (root == NULL) 75 | { 76 | return; 77 | } 78 | else 79 | { 80 | cout << root->data << "->"; 81 | preorder(root->left); 82 | preorder(root->right); 83 | } 84 | } 85 | 86 | void bstnode::inorder(bstnode *root) 87 | { 88 | if (root == NULL) 89 | { 90 | return; 91 | } 92 | else 93 | { 94 | inorder(root->left); 95 | cout << root->data << "->"; 96 | inorder(root->right); 97 | } 98 | } 99 | 100 | void bstnode::postorder(bstnode *root) 101 | { 102 | if (root == NULL) 103 | { 104 | return; 105 | } 106 | else 107 | { 108 | postorder(root->left); 109 | postorder(root->right); 110 | cout << root->data << "->"; 111 | } 112 | } 113 | 114 | int bstnode::min(bstnode *root) 115 | { 116 | if (root == NULL) 117 | { 118 | cout << "BST is empty"; 119 | return -1; 120 | } 121 | else if (root->left == NULL) 122 | { 123 | cout << root->data; 124 | return root->data; 125 | } 126 | else 127 | { 128 | cout << root->data; 129 | return min(root->left); 130 | } 131 | } 132 | 133 | int bstnode::height(bstnode *root) 134 | { 135 | if (root == NULL) 136 | { 137 | return 0; 138 | } 139 | else 140 | { 141 | int lheight = height(root->left); 142 | int rheight = height(root->right); 143 | if (lheight > rheight) 144 | { 145 | return (lheight + 1); 146 | } 147 | else 148 | { 149 | return (rheight + 1); 150 | } 151 | } 152 | } 153 | 154 | void bstnode::mirror(bstnode *root) 155 | { 156 | if (root == NULL) 157 | { 158 | return; 159 | } 160 | else 161 | { 162 | bstnode *temp; 163 | mirror(root->left); 164 | mirror(root->right); 165 | temp = root->left; 166 | root->left = root->right; 167 | root->right = temp; 168 | } 169 | } 170 | 171 | int main() 172 | { 173 | bstnode *root; 174 | root = NULL; 175 | bstnode b; 176 | char ans; 177 | do 178 | { 179 | cout << "\n1)Insert\n"; 180 | cout << "2)Search\n"; 181 | cout << "3)Preorder\n"; 182 | cout << "4)Inorder\n"; 183 | cout << "5)Postorder\n"; 184 | cout << "6)Minimum in BST\n"; 185 | cout << "7)Number of nodes in BST\n"; 186 | cout << "8)Mirror of BST\n"; 187 | cout << "9)End\n"; 188 | cout << "\nEnter Choice:"; 189 | int ch; 190 | cin >> ch; 191 | switch (ch) 192 | { 193 | case 1: 194 | int val; 195 | cout << "\nEnter value to be inserted:"; 196 | cin >> val; 197 | root = b.insert(root, val); 198 | break; 199 | case 2: 200 | int num; 201 | cout << "\nEnter value to be searched:\n"; 202 | cin >> num; 203 | if (b.search(root, num)) 204 | { 205 | cout << "\nFound\n"; 206 | } 207 | else 208 | { 209 | cout << "\nNot Found\n"; 210 | } 211 | break; 212 | case 3: 213 | cout << "\nPreorder Traversal\n"; 214 | b.preorder(root); 215 | break; 216 | case 4: 217 | cout << "\nInorder Traversal\n"; 218 | b.inorder(root); 219 | break; 220 | case 5: 221 | cout << "\nPostorder Traversal\n"; 222 | b.postorder(root); 223 | break; 224 | case 6: 225 | cout << "\nMinimum in BST\n"; 226 | b.min(root); 227 | break; 228 | case 7: 229 | cout << "Number of nodes in BST:" << b.height(root); 230 | break; 231 | case 8: 232 | cout << "\nBefore Swapping\n"; 233 | b.inorder(root); 234 | b.mirror(root); 235 | cout << "\nAfter Swapping\n"; 236 | b.inorder(root); 237 | break; 238 | case 9: 239 | exit(0); 240 | } 241 | } while (true); 242 | } 243 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/11F.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | class tel 8 | { 9 | public: 10 | int rollNo, roll1; 11 | char name[10]; 12 | char div; 13 | char address[20]; 14 | 15 | void accept() 16 | { 17 | cout << "\n\tEnter Roll Number: "; 18 | cin >> rollNo; 19 | cout << "\n\tEnter the Name: "; 20 | cin >> name; 21 | cout << "\n\tEnter the Division: "; 22 | cin >> div; 23 | cout << "\n\tEnter the Address: "; 24 | cin >> address; 25 | } 26 | 27 | void accept2() 28 | { 29 | cout << "\n\tEnter the Roll No. to modify: "; 30 | cin >> rollNo; 31 | } 32 | 33 | void accept3() 34 | { 35 | cout << "\n\tEnter the name to modify: "; 36 | cin >> name; 37 | } 38 | 39 | int getRollNo() 40 | { 41 | return rollNo; 42 | } 43 | 44 | void show() 45 | { 46 | cout << "\n\t" << rollNo << "\t\t" << name << "\t\t" << div << "\t\t" << address; 47 | } 48 | }; 49 | 50 | int main() 51 | { 52 | int i, n, ch, ch1, rec, start, count, add, n1, add2, start2, n2, y, a, b, on, oname, add3, start3, n3, y1, add4, start4, n4; 53 | char name[20], name2[20]; 54 | tel t1; 55 | count = 0; 56 | fstream g, f; 57 | 58 | do 59 | { 60 | cout << "\n>>>>>>>>>>>>>>>>>>>>>>MENU<<<<<<<<<<<<<<<<<<<<"; 61 | cout << "\n1.Insert and overwrite\n2.Show\n3.Search & Edit(number)\n4.Search & Edit(name)\n5.Search & Edit(onlynumber)\n6.Search & edit(only name)\n 7.Delete a Student Record\n 8.Exit\n\tEnter the Choice: "; 62 | cin >> ch; 63 | 64 | switch (ch) 65 | { 66 | case 1: 67 | f.open("StuRecord.txt", ios::out); 68 | x: 69 | t1.accept(); 70 | f.write((char *)&t1, sizeof(t1)); 71 | cout << "\nDo you want to enter more records?\n1.Yes\n2.No"; 72 | cin >> ch1; 73 | if (ch1 == 1) 74 | goto x; 75 | else 76 | { 77 | f.close(); 78 | break; 79 | } 80 | 81 | case 2: 82 | f.open("StuRecord.txt", ios::in); 83 | f.read((char *)&t1, sizeof(t1)); 84 | // cout<<"\n\tRoll No.\t\tName \t\t Division \t\t Address"; 85 | while (f) 86 | { 87 | t1.show(); 88 | f.read((char *)&t1, sizeof(t1)); 89 | } 90 | f.close(); 91 | break; 92 | 93 | case 3: 94 | cout << "\nEnter the roll number you want to find: "; 95 | cin >> rec; 96 | f.open("StuRecord.txt", ios::in | ios::out); 97 | f.read((char *)&t1, sizeof(t1)); 98 | while (f) 99 | { 100 | if (rec == t1.rollNo) 101 | { 102 | cout << "\nRecord found"; 103 | add = f.tellg(); 104 | f.seekg(0, ios::beg); 105 | start = f.tellg(); 106 | n1 = (add - start) / sizeof(t1); 107 | f.seekp((n1 - 1) * sizeof(t1), ios::beg); 108 | t1.accept(); 109 | f.write((char *)&t1, sizeof(t1)); 110 | f.close(); 111 | count++; 112 | break; 113 | } 114 | f.read((char *)&t1, sizeof(t1)); 115 | } 116 | if (count == 0) 117 | cout << "\nRecord not found"; 118 | f.close(); 119 | break; 120 | 121 | case 4: 122 | cout << "\nEnter the name you want to find and edit: "; 123 | cin >> name; 124 | f.open("StuRecord.txt", ios::in | ios::out); 125 | f.read((char *)&t1, sizeof(t1)); 126 | while (f) 127 | { 128 | y = (strcmp(name, t1.name)); 129 | if (y == 0) 130 | { 131 | cout << "\nName found"; 132 | add2 = f.tellg(); 133 | f.seekg(0, ios::beg); 134 | start2 = f.tellg(); 135 | n2 = (add2 - start2) / sizeof(t1); 136 | f.seekp((n2 - 1) * sizeof(t1), ios::beg); 137 | t1.accept(); 138 | f.write((char *)&t1, sizeof(t1)); 139 | f.close(); 140 | break; 141 | } 142 | f.read((char *)&t1, sizeof(t1)); 143 | } 144 | break; 145 | 146 | case 5: 147 | cout << "\nEnter the roll number you want to modify: "; 148 | cin >> on; 149 | f.open("StuRecord.txt", ios::in | ios::out); 150 | f.read((char *)&t1, sizeof(t1)); 151 | while (f) 152 | { 153 | if (on == t1.rollNo) 154 | { 155 | cout << "\nNumber found"; 156 | add3 = f.tellg(); 157 | f.seekg(0, ios::beg); 158 | start3 = f.tellg(); 159 | n3 = (add3 - start3) / sizeof(t1); 160 | f.seekp((n3 - 1) * (sizeof(t1)), ios::beg); 161 | t1.accept2(); 162 | f.write((char *)&t1, sizeof(t1)); 163 | f.close(); 164 | break; 165 | } 166 | f.read((char *)&t1, sizeof(t1)); 167 | } 168 | break; 169 | 170 | case 6: 171 | cout << "\nEnter the name you want to find and edit: "; 172 | cin >> name2; 173 | f.open("StuRecord.txt", ios::in | ios::out); 174 | f.read((char *)&t1, sizeof(t1)); 175 | while (f) 176 | { 177 | y1 = (strcmp(name2, t1.name)); 178 | if (y1 == 0) 179 | { 180 | cout << "\nName found"; 181 | add4 = f.tellg(); 182 | f.seekg(0, ios::beg); 183 | start4 = f.tellg(); 184 | n4 = (add4 - start4) / sizeof(t1); 185 | f.seekp((n4 - 1) * sizeof(t1), ios::beg); 186 | t1.accept3(); 187 | f.write((char *)&t1, sizeof(t1)); 188 | f.close(); 189 | break; 190 | } 191 | f.read((char *)&t1, sizeof(t1)); 192 | } 193 | break; 194 | 195 | case 7: 196 | int roll; 197 | cout << "Please Enter the Roll No. of Student Whose Info You Want to Delete: "; 198 | cin >> roll; 199 | f.open("StuRecord.txt", ios::in); 200 | g.open("temp.txt", ios::out); 201 | f.read((char *)&t1, sizeof(t1)); 202 | while (!f.eof()) 203 | { 204 | if (t1.getRollNo() != roll) 205 | g.write((char *)&t1, sizeof(t1)); 206 | f.read((char *)&t1, sizeof(t1)); 207 | } 208 | cout << "The record with the roll no. " << roll << " has been deleted." << endl; 209 | f.close(); 210 | g.close(); 211 | remove("StuRecord.txt"); 212 | rename("temp.txt", "StuRecord.txt"); 213 | break; 214 | 215 | case 8: 216 | cout << "\n\tThank you"; 217 | break; 218 | } 219 | } while (ch != 8); 220 | 221 | return 0; 222 | } 223 | -------------------------------------------------------------------------------- /Data Structures and Algorithms/9D.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | using namespace std; 5 | 6 | class dictionary; 7 | 8 | class avlnode 9 | { 10 | string keyword; 11 | string meaning; 12 | avlnode *left, *right; 13 | int bf; 14 | 15 | public: 16 | avlnode() 17 | { 18 | keyword = '\0'; 19 | meaning = '\0'; 20 | left = right = NULL; 21 | bf = 0; 22 | } 23 | 24 | avlnode(string k, string m) 25 | { 26 | keyword = k; 27 | meaning = m; 28 | left = right = NULL; 29 | bf = 0; 30 | } 31 | 32 | friend class dictionary; 33 | }; 34 | 35 | class dictionary 36 | { 37 | avlnode *par, *loc; 38 | 39 | public: 40 | avlnode *root; 41 | 42 | dictionary() 43 | { 44 | root = NULL; 45 | par = loc = NULL; 46 | } 47 | 48 | void accept(); 49 | void insert(string key, string mean); 50 | void LLrotation(avlnode *, avlnode *); 51 | void RRrotation(avlnode *, avlnode *); 52 | void inorder(avlnode *root); 53 | void deletekey(string key); 54 | void descending(avlnode *); 55 | void search(string); 56 | void update(string, string); 57 | }; 58 | 59 | void dictionary::descending(avlnode *root) 60 | { 61 | if (root) 62 | { 63 | descending(root->right); 64 | cout << root->keyword << " " << root->meaning << endl; 65 | descending(root->left); 66 | } 67 | } 68 | 69 | void dictionary::accept() 70 | { 71 | string key, mean; 72 | cout << "Enter keyword: " << endl; 73 | cin >> key; 74 | cout << "Enter meaning: " << endl; 75 | cin >> mean; 76 | insert(key, mean); 77 | } 78 | 79 | void dictionary::LLrotation(avlnode *a, avlnode *b) 80 | { 81 | cout << "LL rotation" << endl; 82 | a->left = b->right; 83 | b->right = a; 84 | a->bf = b->bf = 0; 85 | } 86 | 87 | void dictionary::RRrotation(avlnode *a, avlnode *b) 88 | { 89 | cout << "RR rotation" << endl; 90 | a->right = b->left; 91 | b->left = a; 92 | a->bf = b->bf = 0; 93 | } 94 | 95 | void dictionary::insert(string key, string mean) 96 | { 97 | if (!root) 98 | { 99 | root = new avlnode(key, mean); 100 | cout << "ROOT CREATED" << endl; 101 | return; 102 | } 103 | 104 | avlnode *a, *pa, *p, *pp; 105 | p = a = root; 106 | pp = NULL; 107 | 108 | while (p) 109 | { 110 | if (p->bf) 111 | { 112 | a = p; 113 | pa = pp; 114 | } 115 | if (key < p->keyword) 116 | { 117 | pp = p; 118 | p = p->left; 119 | } 120 | else if (key > p->keyword) 121 | { 122 | pp = p; 123 | p = p->right; 124 | } 125 | else 126 | { 127 | cout << "Already exist" << endl; 128 | return; 129 | } 130 | } 131 | 132 | avlnode *y = new avlnode(key, mean); 133 | 134 | if (key < pp->keyword) 135 | { 136 | pp->left = y; 137 | } 138 | else 139 | { 140 | pp->right = y; 141 | } 142 | 143 | int d; 144 | avlnode *b, *c; 145 | a = pa = NULL; 146 | p = a = root; 147 | pp = NULL; 148 | 149 | while (p != y) 150 | { 151 | if (key > p->keyword) 152 | { 153 | pp = p; 154 | p = p->right; 155 | } 156 | else 157 | { 158 | pp = p; 159 | p = p->left; 160 | } 161 | } 162 | 163 | if (!(a->bf) || !(a->bf + d)) 164 | { 165 | a->bf += d; 166 | return; 167 | } 168 | 169 | if (d == 1) 170 | { 171 | b = p = a->right; 172 | d = -1; 173 | 174 | if (key > a->keyword) 175 | { 176 | LLrotation(a, b); 177 | } 178 | else 179 | { 180 | cout << "LR rotation" << endl; 181 | c = b->right; 182 | b->right = c->left; 183 | a->left = c->right; 184 | c->left = b; 185 | c->right = a; 186 | 187 | switch (c->bf) 188 | { 189 | case 1: 190 | a->bf = 0; 191 | b->bf = -1; 192 | break; 193 | case -1: 194 | a->bf = 1; 195 | b->bf = 0; 196 | break; 197 | case 0: 198 | a->bf = 0; 199 | b->bf = 0; 200 | break; 201 | } 202 | 203 | c->bf = 0; 204 | b = c; 205 | } 206 | } 207 | else if (d == -1) 208 | { 209 | b = p = a->left; 210 | d = 1; 211 | 212 | if (key < a->keyword) 213 | { 214 | RRrotation(a, b); 215 | } 216 | else 217 | { 218 | cout << "RL rotation" << endl; 219 | c = b->left; 220 | a->right = c->left; 221 | b->left = c->right; 222 | c->left = a; 223 | c->right = b; 224 | 225 | switch (c->bf) 226 | { 227 | case 1: 228 | a->bf = 0; 229 | b->bf = -1; 230 | break; 231 | case -1: 232 | a->bf = 1; 233 | b->bf = 0; 234 | break; 235 | case 0: 236 | a->bf = 0; 237 | b->bf = 0; 238 | break; 239 | } 240 | 241 | c->bf = 0; 242 | b = c; 243 | } 244 | } 245 | 246 | if (!pa) 247 | { 248 | root = b; 249 | } 250 | else if (a == pa->left) 251 | { 252 | pa->left = b; 253 | } 254 | else 255 | { 256 | pa->right = b; 257 | } 258 | 259 | cout << "AVL tree created!!" << endl; 260 | } 261 | 262 | void dictionary::search(string key) 263 | { 264 | loc = NULL; 265 | par = NULL; 266 | 267 | if (root == NULL) 268 | { 269 | cout << "Tree not created" << endl; 270 | return; 271 | } 272 | 273 | avlnode *ptr = root; 274 | 275 | while (ptr != NULL) 276 | { 277 | if (ptr->keyword == key) 278 | { 279 | break; 280 | } 281 | else if (key < ptr->keyword) 282 | { 283 | par = ptr; 284 | ptr = ptr->left; 285 | } 286 | else 287 | { 288 | par = ptr; 289 | ptr = ptr->right; 290 | } 291 | } 292 | 293 | if (loc == NULL) 294 | { 295 | cout << "Not found" << endl; 296 | } 297 | } 298 | 299 | void dictionary::update(string oldkey, string newmean) 300 | { 301 | search(oldkey); 302 | loc->meaning = newmean; 303 | cout << "UPDATE SUCCESSFUL" << endl; 304 | } 305 | 306 | void dictionary::deletekey(string key) 307 | { 308 | // Not implemented 309 | } 310 | 311 | void dictionary::inorder(avlnode *root) 312 | { 313 | if (root) 314 | { 315 | inorder(root->left); 316 | cout << root->keyword << " " << root->meaning << endl; 317 | inorder(root->right); 318 | } 319 | } 320 | 321 | int main() 322 | { 323 | string k, m; 324 | dictionary d; 325 | int ch; 326 | string key, mean; 327 | 328 | do 329 | { 330 | cout << "1. Insert" << endl; 331 | cout << "2. Update" << endl; 332 | cout << "3. Ascending" << endl; 333 | cout << "4. Descending" << endl; 334 | cout << "5. Display" << endl; 335 | cout << "6. Quit" << endl; 336 | cin >> ch; 337 | 338 | switch (ch) 339 | { 340 | case 1: 341 | cout << "Enter word and its meaning" << endl; 342 | cin >> k >> m; 343 | d.insert(k, m); 344 | break; 345 | 346 | case 2: 347 | cout << "Enter key whose meaning to update" << endl; 348 | cin >> key; 349 | cout << "Enter new meaning" << endl; 350 | cin >> mean; 351 | d.update(key, mean); 352 | break; 353 | 354 | case 3: 355 | d.inorder(d.root); 356 | break; 357 | 358 | case 4: 359 | cout << "Descending" << endl; 360 | d.descending(d.root); 361 | break; 362 | 363 | case 5: 364 | d.inorder(d.root); 365 | break; 366 | 367 | default: 368 | break; 369 | } 370 | } while (ch != 6); 371 | 372 | return 0; 373 | } 374 | --------------------------------------------------------------------------------