File Structure Assignment One

download File Structure Assignment One

of 18

Transcript of File Structure Assignment One

  • 8/7/2019 File Structure Assignment One

    1/18

    PRESENTS

    F i l eSTRUCTURE

    A s s i g n m e n t O N E

    MAZEBLAGWA

  • 8/7/2019 File Structure Assignment One

    2/18

    1

    Identification

    MAZEBy : Mahmoud Fayyaz Num : 73

    Notes :

  • 8/7/2019 File Structure Assignment One

    3/18

  • 8/7/2019 File Structure Assignment One

    4/18

    3

    ProblemStatement

    Required to implement a queue(FIFO ADT).

    Behavior of the queue:

    Push(x): insert element x to the queue.

    Pop(): retrieve and remove first inserted

    element in the queue. isEmpty(): return if the queue is empty or

    not.

    Sizeof(): return the current number of

    elements in the queue.

    Empty(): clears the queue.

    Required to implement a stack (LIFO ADT).

    Behavior of the stack:

    Push(x): insert element x to the stack.

    Pop(): retrieve and remove last inserted

    element in the stack. isEmpty(): return if the stack is empty or

    not.

    Sizeof(): return the current number of

    elements in the stack.

    Empty(): clears the stack.

  • 8/7/2019 File Structure Assignment One

    5/18

    4

    ProblemStatement

    required to write a program to solve a simple

    maze game.

    Maze will be represented as a 2D matrix

    with the following properties:

    Each cell in the matrix may be anopen space or a wall.

    Start point is the upper left cell, and

    end point is the lower right cell

    (Both cells must not be walls).

    There must be at least one solution

    for the maze (i.e. a road of open

    spaces from start point to end

    point).

    The target of your program is to find a

    solution of the maze with two methods,

    the first one using your stack and the

    second one using your queue.

    The input to your program should be afile maze.txt, its format will be as the

    following:

    It will contain comma separated

    numbers.

    The first number is the number of

    rows.

  • 8/7/2019 File Structure Assignment One

    6/18

    5

    ProblemStatement

    Make an option in your program to randomly

    generate a valid maze. Input in this case will

    be only the size of the maze (i.e. number ofrows and number of columns). You should

    give a visual way to test the generated maze.

    The second number is the number of

    columns.

    The following numbers are the 1-

    based indices of a row major

    representation of the wall cells. The output of your program should be

    two files out_stack.txt, out_queue.txt.

    Output files should contain comma

    separated numbers. These numbers are

    the 1-based indices of a raw major

    representation of a valid solution of the

    maze.

  • 8/7/2019 File Structure Assignment One

    7/18

    6

    Ovarall system

    The System Consists of 23 file:

    6 (dot)exe files:

    AssignmentOneFileStructureStackIm

    p.exe to test the stack alone.

    AssignmentOneFileStructureQueueImp.exe to test the queue alone,

    AssignmentOneFileStructureStackVe

    rsion.exe to solve the maze using

    stack,

    AssignmentOneFileStructureQueueV

    ersion.exe to solve the maze using

    queue.

    MazeGenerator.exe to generate

    random maze.

    MazeGenerator(2).exe to generate

    random maze.

    5 (dot)jar files:

    PathCorrectnessChecker1BasedRowMajor.StackVersionjar.jar To check

    validity of the stack path.

    PathCorrectnessChecker1BasedRow

    Major.QueueVersionjar.jar To check

    validity of the queue path.

  • 8/7/2019 File Structure Assignment One

    8/18

    7

    Ovarall system

    CommaToSpaceAdjustor.jar To

    adjust the input.

    MazeCheck.jar To check validity of

    the maze

    MazeView.jar To view the maze 12 I/O Files

    StackTestCasesInput.in

    StackTestCasesOutput.out

    QueueTestCasesInput.in

    QueueTestCasesOutput.out

    MazeGeneration.in

    Maze.in

    MazeCheck.out

    MazeView.out

    StackMazeSolverOutput.out

    StackMazeSolverCheckResult.out

    QueueMazeSolverOutput.out

    QueueMazeSolverCheckResult.out

  • 8/7/2019 File Structure Assignment One

    9/18

    8

    Ovarall system

  • 8/7/2019 File Structure Assignment One

    10/18

    9

    UnderMicroscope

    Stack

    Structure Node

    parameter : element => Data to store

    Next Pointer to a structure => Next in the line

    Class Stack

    Description : Stack is a linked LiFo Data

    Structure implemented the Dummy header

    Node linked list

    Parameter : size integer => number of

    elements in the stack

    head Pointer to a structure => The first

    Dummy Node in the stack

    Behavior : Pop => to get the last inserted

    element in the stack and remove it from the

    stack

    push => to insert in the stack

    top => to get the last inserted element in the

    stack without removing it

    getSize => to get the number of element that

    the stack store till now

    inEmpty => return true if the size = zero

    other wise return false

  • 8/7/2019 File Structure Assignment One

    11/18

    10

    UnderMicroscope

    Stack

    Main

    => for testing the stack

    step 1 : read from file "StackTestCasesInput"

    step 2 : read the operationstep 3 : write the result in

    "StackTestCasesOutput.out"

    -> the operation code

    1 => Push => it takes the first number in the

    file and push it in the stack

    2 => Pop => write and remove the last

    inserted element

    3 => top => write without removing

    4 => size => write the number of elements in

    the stack

    5 => isEmpty => Write true or false

  • 8/7/2019 File Structure Assignment One

    12/18

    11

    UnderMicroscope

    Queue

    Structure Node

    parameter : element => Data to store

    Next Pointer to a structure => Next in the line

    Prev Pointer to a structure => Prev in the line

    Class Queue

    Description : Queue is a linked fiFo Data

    Structure implemented the Dummy header

    and footer Node linked list

    Parameter : size integer => number of

    elements in the queue

    head Pointer to a structure => The first

    Dummy Node in the queue

    head tail to a structure => The last Dummy

    Node in the queue

    Behavior : dequeue => to get the first

    inserted element in the queue and remove it

    from the queue

    enqueue => to insert in the queue

    first => to get the first inserted element in

    the queue without removing it

    getSize => to get the number of element that

    the queue store till nowinEmpty => return true if the size = zero

    other wise return false

  • 8/7/2019 File Structure Assignment One

    13/18

    12

    UnderMicroscope

    Queue

    Main

    => for testing the stack

    step 1 : read from file

    "QueueTestCasesInput.in"step 2 : read the operation

    step 3 : write the result in

    "QueueTestCasesOutput.out"

    -> the operation code

    1 => enqueue => it takes the first number in

    the file and enqueue it in the Queue

    2 => dequeue => write and remove the first

    inserted element

    3 => first => write without removing

    4 => size => write the number of elements in

    the queue

    5 => isEmpty => Write true or false

  • 8/7/2019 File Structure Assignment One

    14/18

    13

    UnderMicroscope

    Stack Maze Solver

    get Start , endVisit(Start)Stack.push(start)

    While (not stack.isEmpty){if (Stack.top() = end) break;current =validNeighbour(Stack.top)if (not current exist){

    Stack.pop();continue

    }stack.push(current)

    }vaildNeighbour(current)

    {if (current has right unvisited )

    return the rightif (current has down unvisited )

    return thedownif (current has lift unvisited )

    return the leftif (current has up unvisited )

    return the up}

  • 8/7/2019 File Structure Assignment One

    15/18

    14

    UnderMicroscope

    Queue Maze Solver

    get Start , endVisit(Start)Queue.enqueue(Start)

    While (not Queue.isEmpty){current = Queue.dequeue()Visit and enqueue all validunvisited neighboursif (end is one of valid neighbor)

    break}

    //Queue Order = n^2 Gets always the shortest path Constant (time of execution depend only on

    n ) //Stack Order = n^2 Not a condition to get the shortest path Execution time vary (from 2n to n^2)

  • 8/7/2019 File Structure Assignment One

    16/18

    15

    UnderMicroscope

    Maze Generation

    Get x, yArray maze[x*y]Fill maze = wall

    For(I 0:x*y){maze[i]=freeif (i in the first row)

    maze[i+1]=freeelse if(I on the last column)

    maze[i-y]=freeelse

    randomif (random)

    maze[i+1]=freeelse

    maze[i-y]=free

    }maze[x*y-1]=free

  • 8/7/2019 File Structure Assignment One

    17/18

    16

    UnderMicroscope

    Maze Generation(1)

    Get x, yArray maze[x*y]Fill maze = wall

    For(I 0:x*y){if(I in an odd row)continuemaze[i]=freeif (i in the first row)

    maze[i+1]=freeelse if(I on the last column)

    maze[i-y]=freeelse

    randomif (random)

    maze[i+1]=freeelse

    maze[i-y]=free}maze[x*y-1]=free

  • 8/7/2019 File Structure Assignment One

    18/18

    UnderMicroscope

    Complementary

    Path Validator

    Check if1) The path starts at the start point2) The path doesnt jump

    3) The path doesnt hit a wall4) The path ends at the end point Maze Validator (fluid fill)

    Color the start with special colorColor the neighbours with the samecolorreturn start color = end color

    Maze View

    Loop on the maze inputIf wall print XElse print *