Mix (C++ and Assembly) Program to Sort Numbers in Descending Order

This post demonstrates how to sort an array of integers using inline assembly in C++. We use basic comparison and swap logic in assembly embedded within a C++ program.

#include<iostream.h>
#include<conio.h>
void main()
{
    int a[5], x, y;
    int i, j;
    cout << "\n Enter 5 Numbers:";
    for(i = 0; i < 5; i++)
    {
        cin >> a[i];
    }
    //Sorting
    for(i = 0; i < 4; i++)
    {
        for(j = 0; j < 4; j++)
        {
            x = a[j];
            y = a[j + 1];
            asm {
                mov ax, x
                mov bx, y
                cmp ax, bx
                jge nxt
                mov cx, ax
                mov ax, bx
                mov bx, cx
                mov x, ax
                mov y, bx
            }
            nxt:
            a[j] = x;
            a[j + 1] = y;
        }
    }
    cout << "\n Sorted Array:";
    for(i = 0; i < 5; i++)
        cout << a[i] << " ";
    getch();
}
Continue reading Mix (C++ and Assembly) Program to Sort Numbers in Descending Order

Implementing Bresenham’s Circle Drawing Algorithm in C++

Bresenham’s circle algorithm is an efficient way to draw a circle using only integer calculations. It eliminates the need for floating-point arithmetic and is widely used in computer graphics.

Below is the implementation of Bresenham’s circle drawing algorithm using C++ and the graphics.h library. This program takes user input for the circle’s center and radius, then uses the algorithm to plot the circle.

Continue reading Implementing Bresenham’s Circle Drawing Algorithm in C++

Implementing Boundary Fill Algorithm in C++

The Boundary Fill Algorithm is a region-filling technique used in computer graphics to fill a connected area with a new colour. Starting from a seed pixel inside the shape, the algorithm recursively colours every neighbouring pixel as long as it does not match the defined boundary colour and has not already been coloured with the new fill colour. It supports 8-connected filling, meaning it spreads to all eight surrounding pixels — including diagonals.

Continue reading Implementing Boundary Fill Algorithm in C++

Implementing Bresenham’s Line Algorithm in C++

Bresenham’s Line Algorithm is one of the most fundamental algorithms in computer graphics. It determines the set of pixels that most closely approximate a straight line between two given endpoints on a raster display. The key advantage of Bresenham’s algorithm over simpler approaches is that it uses only integer arithmetic — no floating-point multiplication or division — making it extremely fast for hardware and software rendering alike.

Continue reading Implementing Bresenham’s Line Algorithm in C++

Implementing 2-D Transformation in C++

2-D Transformations are fundamental operations in computer graphics that change the position, size, or orientation of geometric objects on a 2-D plane. The three basic transformations are Translation (moving an object), Scaling (resizing an object), and Rotation (rotating an object about the origin). This C++ program implements all three transformations on a line segment entered by the user and renders the transformed result using the Turbo C++ graphics.h library.

Continue reading Implementing 2-D Transformation in C++

Implementing Tower of Hanoi Problem in Java

The Tower of Hanoi is a classic mathematical puzzle that elegantly demonstrates the power of recursion. It consists of three rods (pegs) and a number of disks of different sizes that can slide onto any rod. The puzzle begins with all disks stacked in ascending size order on one rod (smallest on top) and the goal is to move the entire stack to another rod.

Three rules must be followed:

  1. Only one disk may be moved at a time.
  2. A disk may only be moved if it is the uppermost disk on its rod.
  3. No disk may be placed on top of a smaller disk.

The minimum number of moves required to solve the puzzle with n disks is 2n − 1. For 3 disks, that’s 7 moves; for 10 disks, 1023 moves.

Continue reading Implementing Tower of Hanoi Problem in Java

Implementation of Stack in Java

A stack is a LIFO (Last In, First Out) abstract data type where all insertions and deletions happen at the same end, called the top. Think of a stack of plates: you always add to the top and remove from the top. Stacks are used everywhere in computing — from function call management to expression evaluation and undo functionality.

In this post, we implement a stack in Java using a fixed-size integer array, with push, pop, peek, and display operations accessible through a menu-driven console program.

Continue reading Implementation of Stack in Java