assignment 1

2
TE-51 ASSIGNMENT 1 DATA STRUCTURES AND ALGORITHMS Submission Date --- 21 / 10/15 before 9 AM Submit a hardcopy of your programs in groups. 1. Create a doubly circular link list of N elements where n is entered by the user. Write functions to create, display and delete the list. The display function called before delete would display the complete list and the same function called after delete should display a message indicating “No elements to delete”. 2. Assume two link lists A and B. A - 2 , 5, 9, 14 , 15, 7 , 2 , 17 , 30 B - 14 , 2 , 9 , 13 , 37 , 8 , 7 28 Write a function to create a list C that contains only those elements that are common in link list A and B. Your program should work for any set of values. 3. Write a program that performs addition of two polynomials using linked lists. Both the polynomials are input by the user. i) Initially ask the user to enter the number of terms for both the polynomials. Number of terms in both the polynomials may vary. ii) The coefficient and exponent of each term of polynomial is input by the user. It is assumed that the user will enter the values in the decreasing order of coefficients. i.e. 3x^4 + 14x^3 +5x^2 +7 It is not compulsory to enter every coefficient. User may skip any coefficient as shown in the above example. Once the user has entered both of the polynomials, the next task is to add them and display the result. Consider the following node and class structure struct Node{ int exponent;

Upload: junaid-afzal

Post on 08-Apr-2016

1 views

Category:

Documents


0 download

DESCRIPTION

chokka

TRANSCRIPT

Page 1: Assignment 1

TE-51

ASSIGNMENT 1

DATA STRUCTURES AND ALGORITHMS

Submission Date --- 21 / 10/15 before 9 AM

Submit a hardcopy of your programs in groups.

1. Create a doubly circular link list of N elements where n is entered by the user. Write functions to create, display and delete the list. The display function called before delete would display the complete list and the same function called after delete should display a message indicating “No elements to delete”.

2. Assume two link lists A and B.A - 2 , 5, 9, 14 , 15, 7 , 2 , 17 , 30B - 14 , 2 , 9 , 13 , 37 , 8 , 7 28

Write a function to create a list C that contains only those elements that are common in link list A and B. Your program should work for any set of values.

3. Write a program that performs addition of two polynomials using linked lists. Both the polynomials are input by the user.

i) Initially ask the user to enter the number of terms for both the polynomials. Number of terms in both the polynomials may vary. ii) The coefficient and exponent of each term of polynomial is input by the user. It is assumed that the user will enter the values in the decreasing order of coefficients. i.e. 3x^4 + 14x^3 +5x^2 +7

It is not compulsory to enter every coefficient. User may skip any coefficient as shown in the above example. Once the user has entered both of the polynomials, the next task is to add them and display the result. Consider the following node and class structure

struct Node{

int exponent;

int coefficient;

Node*Next};

class poly{

Node *head;

public:

poly()

{ exponent=0; coefficient=1; }

// functions to solve the problem };