Node – Single LinkedList Java Source Code

Node is an object which is built for storing information and it’s has a door the the other node, so it’s not storing other node but just the way to the other node. If it is singleNode, that is the node which just has only one way to the other node.

LinkedList? LinkedList is a nodes which is connected each other. If linkedlist cosist of singleNode, we can say that linked list is single-LinkedList. If still being confused by linkedlist try to understand with array : Node == integer data, LinkedList == array, so if linkedlist consist of many integer data which is continued on memory alloctaion, linkedlist consist of nodes which is connected by the pointer to the other node.

public class singleNode {

    private Object info;
    public singleNode next;

    public singleNode(Object info){
        this.info = info;
        next = null;
    }

    public void setInfo(Object info){
        this.info = info;
    }

    public Object getInfo(){
        return this.info;
    }

    public Object popInfo(){
        Object temp = this.info;
        this.info = null;
        return temp;
    }

}

Knight’s Tour C Source Code

Knight’s Tour is recursive and backtrackting algorithm that use brute force to find the solving.

#include "stdio.h"
#include "conio.h"

void printBoard(int**, int);
void clearBoard(int**, int);
void traceKnight(int**, int, int, int, int, int*);

int main(){
    int matrix;
    printf("Input Box Size : ");
    scanf("%d", &matrix);

    /* Board Matrix Building */
    int** board;
    board = (int**) malloc (sizeof(int)* matrix);
    for (int i = 0; i < matrix; i++)
    {
        board[i] = (int*) malloc (sizeof(int)* matrix);
    }

    /* Board Clearing Step */
    clearBoard(board, matrix);

    /* Knight Tracing Step */
    int checker = 0;
    traceKnight(board, matrix, 1, 0, 0, &checker);

    /* Printing the Result */
    printBoard(board,matrix);

    getch();
    return 0;
}

Main recursive function that trace and make the combination step of Knight

void traceKnight(int** board, int matrix, int step, int y, int x, int* checker)
{
    /* Step overboard */
    if (y < 0 || y > matrix-1 || x < 0 || x > matrix - 1)
    {
       return;
    }

    /* Board position has been taken */
    if (board[y][x] != 0)
    {
       return;
    }

    /* Take a step */
    board[y][x] = step;
    *checker = step;

    /* Choosing next step */
    traceKnight(board, matrix, step + 1, y - 2, x - 1, checker);
    traceKnight(board, matrix, step + 1, y - 2, x + 1, checker);
    traceKnight(board, matrix, step + 1, y - 1, x + 2, checker);
    traceKnight(board, matrix, step + 1, y + 1, x + 2, checker);
    traceKnight(board, matrix, step + 1, y + 2, x + 1, checker);
    traceKnight(board, matrix, step + 1, y + 2, x - 1, checker);
    traceKnight(board, matrix, step + 1, y + 1, x - 2, checker);
    traceKnight(board, matrix, step + 1, y - 1, x - 2, checker);

    /* Backtracking Step */
    if (*checker < matrix * matrix)
    {
       board[y][x] = 0;
    }
}
void clearBoard(int** board, int index)
{
    for (int y = 0; y < index; y++)
    {
        for (int x = 0; x < index; x++)
        {
              board[y][x] = 0;
        }
    }
}
void printBoard(int** board, int index)
{
    for (int y = 0; y < index; y++)
    {
        for (int x = 0; x < index; x++)
        {
              printf("%4d", board[y][x]);
        }
        printf("n");
    }
}

Tower of Hanoi C Source Code

#include "stdio.h"
#include "conio.h"

void move(int count, char from, char temp, char to)
{
     if (count == 0)
     {
        return;
     }
     else
     {
         move(count - 1, from, to, temp);
         printf("From : %c To : %cn", from, to);
         move(count - 1, temp, from, to);
     }
}

int main()
{
	int count;
    printf("How Many Plates? : ");
   	scanf("%d", &count);
   	move(count,'A','B','C');
	getch();
	return 0;
}