CS515 Assignment 2 Solved

30.00 $

Category: Tags: ,

Description

Rate this product

1 Description

In this assignment, you need to create a doubly circular linked list where each node is represented as shown in the following figure.

Figure 1: Layout of the node of the linked list

This circular linked list is now used to represent a very large integer number. For an example, if the number is 13242197849762 then the following circular linked list can be used to represent the number.

Figure 2: Layout of the doubly circular linked list

As can be observed that the each data field of the node can accommodate atmost five digits. Accordingly, based on the number of digits in the input, you need to find how many nodes will be needed to represent the number. For the given input number 13242197849762, there are fourteen digits, so three nodes will be needed. The absolute value of the data field of the header node will contain the number of nodes needed to represent the given large number and if the number is negative then the sign of the header node number will be negative. While arranging the digits in the node, the least significant five digits will be placed in the first node then next five least significant digits and so on. One can observe that last node may contain less than five digits depending on the input number.

Similarly, you need to create another doubly linked list to represent the second number. Now perform the following tasks-

  • Compare the two numbers and return appropriate message, e.g. “first number is less than the second number” or “first number is greater than the second number” or “both the numbers are same”.
  • Add the two numbers and store the sum in another doubly circular linked list
  • Subtract the smaller number from the larger number and store the result in another doubly linked list

    Your program must contain a printList() function which will take Header node as argument and print the list in the following form-

    • by traversing the doubly circular linked list of the input number 13242197849762

    • the number should be printed as 1324,21978,49762

    Please note that if the header node data value is 0 then it denotes the number 0 and there will be no other nodes with the header node.

    Also, you need to take the input from an input file name ip.txt and generate the output in an output file name op.txt.

1

2 Sample Input Output

Contents of ip.txt 8888888888 2000000000

After executing the program,
Contents of op.txt file
Comparison result: first number is greater than the second number Addition result: 1,08888,88888
Subtraction result:68888,88888

  • Ass2-vlwxlv.zip