$34.99
Objective To implement Stacks using array and use it to solve the Tower of
Hanoi/ Tower of Brahma/ Lucas’
Tower
Penalty for violating naming convention(s) 5%
There are two tasks in this assignment - Task 1 and Task 2. The solution for Task 1 must be used to solve Task 2 and the evaluation will be based on the output of Task 2.
Task 1
The objective of this task is to implement Stacks using arrays. You need to implement PUSH and POP operations. There should be checks for Stack Overflow and Stack Underflow. The maximum size of stacks must be n, which will be given as a command-line argument.
Task 2
The objective of this task is to solve the Tower of Hanoi/ Tower of Brahma/ Lucas’ Tower (ToH). In TOH, there are three poles A, B, and C. There are n disks each of them has a different diameter. Initially A contains all these n disks in the increasing order of diameter (the largest disk is at the bottom of the pole).
Objective: To move all the n disks to the pole C by following the below rules:
(i) only one disk can be moved at a time;
(ii) each move consists of taking the upper disk from one of the poles and placing it on top of another pole or on an empty pole;
(iii) a disk cannot be placed on top of a disk with less diameter.
While solving this problem, you have to use three stacks A, B, C in place of three poles and each move consists of popping one element from one stack and pushing that element to another stack. Initially all disks are to be pushed to the stack A.
Command-line argument:
Your program should receive one command-line argument: the number n of disks. You can assume that the kth disk has a diameter k units.
Output
The output of your program should be in a file named ‘toh.txt’. Each line should denote a stack operation. The first n lines must be “Push disk <k> to Stack A”, where k takes values n to 1 (in decreasing order). This is required to make sure that all n disks are in Stack A before solving the problem. Then the remaining stack operations must be written in order to achieve the goal,
i.e., to place all disks in Stack C in the same order in which they present in Stack A initially. If the stack operation is Push the disk 3 to Stack B, then the corresponding line must be “Push disk 3 to Stack B”. If the stack operation is Pop the disk 4 from Stack B, then the corresponding line must be “Pop disk 4 from Stack B”. In short, every line must have six words where each two adjacent words are separated by a single white space.
Word 1: “Push” or “Pop”
Word 2: “disk”
Word 3: <the-disk-number>
Word 4: “to” (if Word 1 is “Push”) or “from” (if Word 1 is “Pop”)
Word 5: “Stack”
Word 6: “A” or “B” or “C”
Submission
● The program you submit should output: toh.txt when we run the program for evaluation.
● Test well before submission. Some sample outputs are attached.
● Follow some coding style uniformly. Provide proper comments in your code.
Evaluation