Implementation of Dijkstra Algorithm in C++

Dijkstra’s Algorithm is a classic greedy algorithm for finding the shortest path from a single source vertex to all other vertices in a weighted graph with non-negative edge weights. It maintains a set of visited vertices and a distance array. At each step it selects the unvisited vertex with the smallest known distance, marks it visited, and relaxes (updates) the distances of its neighbours. This process repeats until all vertices have been visited.

This C++ program reads a cost matrix from the user (entering -1 for absent edges and 0 for self-loops), runs Dijkstra’s algorithm from a user-specified source vertex, and prints the shortest distance and parent vertex for every node.

Continue reading Implementation of Dijkstra Algorithm in C++

Implementation of Distance Vector Routing (DVR) Algorithm in C++

This is an outdated post! Please click here to see latest version of Implementation of Distance Vector Routing (DVR) Algorithm in C++

The Distance Vector Routing (DVR) Algorithm is a fundamental routing algorithm used in computer networks to determine the shortest path between nodes. It is based on the Bellman-Ford algorithm and operates by sharing routing tables among directly connected nodes to update their knowledge about the shortest paths.

In this blog post, we will discuss the implementation of the DVR algorithm in C++, go through the code step by step, and explain its output.

Continue reading Implementation of Distance Vector Routing (DVR) Algorithm in C++

C++ Program to Copy Text from One File to Another

File I/O is a fundamental skill in systems programming. This C++ program demonstrates how to copy the contents of one text file to another using standard C file functions: fopen(), fgetc(), fputc(), feof(), and fclose(). The program opens the source file in read mode and the destination file in write mode, then reads characters one at a time from the source and writes each character to the destination until the end of the source file is reached.

This approach is a classic example of character-level file copying — simple, portable, and easy to trace. It also shows basic error handling: if the source file cannot be opened (e.g., path does not exist), the program reports an error instead of proceeding.

Continue reading C++ Program to Copy Text from One File to Another

Mix (Assembly and C++) Program to Find Greatest of Two Numbers

This program demonstrates how to compare two integers using 8086 inline assembly in C++. By leveraging assembly instructions like sub and conditional jump js, the program determines which number is greater.

#include<iostream.h>
#include<conio.h>

void main() {
    clrscr();
    short a;
    short b;

    cout << "\n Enter First Number:";
    cin >> a;

    cout << "\n Enter Second Number:";
    cin >> b;

    asm mov ax, 0000h        // Clear AX
    asm mov bx, 0000h        // Clear BX
    asm mov ax, a            // Load first number into AX
    asm mov bx, b            // Load second number into BX
    asm sub ax, bx           // Subtract BX from AX
    asm js true              // Jump if result is negative (AX < BX)

    cout << "\n " << a << " is greater than " << b;
    asm jmp end              // Skip 'true' block

true:
    cout << "\n " << b << " is greater than " << a;

end:
    getch();
}
Continue reading Mix (Assembly and C++) Program to Find Greatest of Two Numbers

Implementation of Hamming Code in C++

The Hamming Code is an error-detection and error-correction technique developed by Richard Hamming. It introduces redundancy bits (also called parity bits) into a data frame at specific positions that are powers of 2 (positions 1, 2, 4, 8, …). Each redundancy bit covers a set of data bits determined by the binary representation of their positions. At the receiver’s end, the syndrome bits are recalculated and XOR-compared with the received parity bits — a non-zero result identifies the exact bit position where an error occurred.

This C++ program takes a data frame and the number of redundancy bits as input, inserts parity bits at the appropriate positions, simulates a single-bit error at a user-specified location, recalculates the syndrome, and reports the error position.

Continue reading Implementation of Hamming Code in C++

8086 Assembly Program to Print ‘hello’ using 09H

DOS interrupt 21h function 09h is the easiest way to print a string in 8086 assembly: point DX at your string, set AH to 09h, call INT 21h, and you’re done. No loop, no character counter, no BX pointer arithmetic. The tradeoff is a minor convention: the string must end with a $ character so DOS knows where to stop. Compare this with the function 02h character loop approach — 09h is cleaner for fixed strings; 02h gives you more control for dynamic output.

Continue reading 8086 Assembly Program to Print ‘hello’ using 09H

Interrupting BIOS with 8086 Assembly Program

INT 10h is the BIOS video interrupt — completely separate from the DOS INT 21h family. Where INT 21h talks to the operating system, INT 10h talks directly to the video BIOS to control the screen: cursor shape, cursor position, character output, screen modes. This short program demonstrates two of those functions: setting the cursor shape and moving it to a specific screen position.

Continue reading Interrupting BIOS with 8086 Assembly Program