0% found this document useful (0 votes)
28 views

LabSheet1 Final

The document provides instructions for a lab assignment to implement set and iterator abstract data types (ADTs) using linked lists, including functions to create and manipulate sets, initialize and traverse iterators, and a driver program to read elements from files and add them to sets. Students are asked to write code for set and iterator operations in separate files, following coding conventions for multi-file programs, and submit their work along with sample input and output files.

Uploaded by

nextprashant
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

LabSheet1 Final

The document provides instructions for a lab assignment to implement set and iterator abstract data types (ADTs) using linked lists, including functions to create and manipulate sets, initialize and traverse iterators, and a driver program to read elements from files and add them to sets. Students are asked to write code for set and iterator operations in separate files, following coding conventions for multi-file programs, and submit their work along with sample input and output files.

Uploaded by

nextprashant
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

BIRLA INSTITUTE OF TECHNOLOGY & SCIENCE, PILANI

First Semester 2010-2011

CS / IS C363 Data Structures and Algorithms

[Section 1 – Monday, 9th August]

Lab Sheet – 1 [Duration: 2 hours and 30 minutes]

General Instructions for Programming


Important Instruction: Append your Id no at the end of the file name. e.g. main_f2008XXX.c

Linux command to download the labsheet and support files to the local machine
$scp -r <username>@blade3:\<foldername> .
Linux command to upload all the program files back to the server.

$ scp -r <dir containing their files> username@blade3:~

1. All inputs to the program must be either (a) command line arguments (b) or read from a file
(other than stdin). DO NOT READ anything from stdin and DO NOT USE PROMPTS like
“Please enter a number …”.
2. You are required to write the output to a file (other than stdout) and errors if any to a different
output channel (stderr or another file).
3. Use standard C coding conventions for multi-file programs. Separate the following: interfaces
of functions (use a “.h” file), data type definitions (use another “.h” file), ADT / algorithm
implementation (use a “.c” file), and driver/test code (use another ”.c” code).

Problem Statement

A Set is a collection of elements. The basic operations on sets are membership of an element, set union,
set intersection, set difference etc. Implement SetADT which represents sets as sorted linked lists where
each node of the list represents an element of the set. Various operations on sets are then performed by
traversing the corresponding linked lists. An Iterator is used as an interface to traverse the lists
representing sets. Iterator maintains the head of the list and current position as cursor, and the
number of elements yet to access.

Write the following functions to implement above ADTs in the specified files.

(A) Functions in SetADT (file: SetOps.c):

1. Set createSet()
This function creates an empty set and returns it.
2. boolean isMember(Set S, Element e)
This function uses the Iterator interface to traverse through the elements of the set S and
returns true if the element e is found belonging to the set S, else returns false.

3. Set addElement(Set S, Element e)


This function uses the Iterator interface to traverse through the existing elements of the
set S and inserts the new element in the sorted order.

4. Set deleteElement(Set S, Element e)


This function deletes an element e from the set and returns the modified set if e belongs
to the set else returns the set intact.

5. Set setUnion(Set S1, Set S2)


This function creates a new set which is the union of the two sets S1 and S2.

6. Set setIntersection(Set S1, Set S2)


This function creates a new set which is the Intersection of the two sets S1 and S2.

(B) Functions in IteratorADT (file: IteratorOps.c):

1. ITERATOR initIterator(Set S)
This function initializes the Iterator to access the elements of the set S.

2. boolean hasMoreElements(ITERATOR I)
This function returns true if there are more elements to access and false if end of the list
has been reached.

3. ITERATOR moveNext(ITERATOR I)
This function returns updates the iterator I by moving to the next element.

(C)Function in main.c:

1. Set makeSet(char *filename)


This function opens a given file, reads elements one at a time and adds each element to a
given set, using the operations in set ADT. This function should be part of the driver code (i.e.
main.c).

Support files: SetDef.h, NodeDef.h, IteratorDef.h, input1.dat, input2.dat

Deliverables: SetOps.h, SetOps.c, IteratorOps.h, IteratorOps.c, main.c, make file, output.dat

You might also like