Sie sind auf Seite 1von 4

BITS, PILANI (RAJASTHAN)

First Semester 2011-12


CS C341/ IS C361 Data Structures and Algorithms
Lab#1 SEC-4 (Thursday, 11th Aug.)
ADT ShuffleList
Duration: 2 hours 30 minutes
General Instructions for Programming
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). In general, each
module has to be written in separate c files.
4. All files related to a lab must be put inside a single directory by the name of the lab (lab1, lab2,
etc.).

Problem Statement
Write a program to riffle shuffle three country teams of robots to build the world team
(named SuperR) of robots. Each country has number of state teams. State team consists
of number of robots. First we need to create country team by taking the robot with
maximum number of features from the first state team of robots as first element of the
country team then the first robot with maximum number of features from the second state
team of robots as second element of the country team and so on and then second
maximum of first state and so on till all the elements of state teams are exhausted.
Likewise we create all country teams. Finally we create the world team by following the
same procedure.

Data Structures to be used


1. Country Team: stores country name and number of state teams (i.e. size) and
maintains the list of states. In a country, the number of states is not fixed.
There are three countries in all.
2. State Team: stores state name and number of robots. This maintains the list of
robots in a state team. The number of robots in a team is not fixed.
3. Robot Details:

a.
b.
c.
d.
e.
f.

RID: Unique identity number of the robot (i.e. 1001,1002 etc.)


RType : Category to which robot belongs (i.e. T1, T2 etc.)
RMake : Company name (i.e. Samsung, Sony etc.)
Rweight: Robot weight (i.e. 100.5, 200.8 etc.)
Rfeatures: Number of features (i.e. 23,34 etc.)
Rspeed: Robot Speed (23.5, 35.5 etc.)

Instance of StateTeam is as follows

R1

R2

R3

R4
NULL

RAJ

first

Step 1: Create new type definition(s) (file: Team.h)


(a) Create a type definition for a Robot with all the above details of Robot.
(b) Create a type definition for a node in a linked list that contains a Robot. You need
to create a linked list of Robot.
(c) Create a type definition for a StateRTeam which stores robot list as a linked list.
(d) Create a type definition for a CountryRTeam as an array of structure containing
states as a linked list.
Step 2: Design Team ADT with the following Operations: (file: TeamOps.h)
Following are the Team ADT operations.
(a) Team createTeamR():creates an empty list.
(b) Team populateList(Team r,FILE *f1): reads robot data from the file and insert
it into the list.
(c) void printList(LINK head,FILE *f1): prints the list data into a output file
(d) Team InsertRobot(Robot rl, Team sl): adds the robot element in the linked list.
Step 3: Implement the above operations for TeamADT. (file: TeamOps.c)
Step 4: Create driver file (file worldteam.c) that can read input files corresponding to
various country teams. Write a main procedure with command line arguments for three
input file names and an output file name.
Also write the procedure shuffleList
(a) Team shuffleRTeam(StateRTeam *srt):
Procedure shuffleList creates a country team by taking the robot with max
number of features from first state team and then robot with max number of
features from second state team and so on. This will continue till end of list.

In the end, when only one state team is left, append all the elements in
decreasing order of feature values.
(b) Create the worldR with 10 elements using above shuffle procedure.
The code can be executed by invoking the executable as
./EXEFILE country.txt state.txt robotdata.txt outputfile.
Example for shuffling based on Number of features:
RID
RType RMake
Rweight
Rfeatures
Rspped
(TeamA)List1:
1001
T2
Microsoft
23.000000
36
34.000000
1002
T1 Samsung
34.000000
35
34.000000
-------------------------(TeamB)List2:
2001
R3
IBM
2002
R2
Microsoft
2003
R1
IndiaSamsung
--------------------------

45.000000
23.000000
34.000000

33
32
31

23.000000
34.000000
34.00000

ShuffleList:
2003
R1
IndiaSamsung
2002
R2
Microsoft
1002
T1
Samsung
2001
R3
IBM
1001
T2
Microsoft
--------------------------

34.000000
23.000000
34.000000
45.000000
23.000000

31
32
35
33
36

34.000000
34.000000
34.000000
23.000000
34.000000

Files :
Input files: country.txt, state.txt, robotdata.txt
Deliverables : Team.h, TeamOps.h, TeamOps.c, worldteam.c.,output.txt
Create a Makefile.
Sample Input files
Country.txt
Country Name$No. of state Teams
India$4
China$2
Japan$2
StateTeams.txt
CountryName$StateTeamName$Number of robots
India$RAJ$3
India$MS$2
India$HP$1
India$UP$2
China$WR$2
China$ER$1
Japan$HK$2
Japan$HU$1

Robots.txt
India$RAJ
1001$T1$Sony$34.4$34$24.5
1002$T2$Samsung$31.4$26$24.5
1003$T1$Tera$24.4$25$24.5
India$MS
2001$T1$Joky$24.4$11$14.5
2002$T2$Sony$31.4$12$44.5
India$HP
3001$T1$HP$31.4$23$24.5
India$UP
4001$T1$Nokia$54.4$54$25.5
4002$T2$Sony$24.4$22$21.5
China$WR
5001$T2$Motorola$38.4$56$22.5
5002$T1$Sony$14.4$12$14.5
China$ER
6001$T1$HP$34.4$44$24.5
Japan$HK
7001$T2$Mono$38.4$24$42.5
7002$T1$Sony$14.4$42$19.5
Japan$HU
8001$T1$HP$34.4$26$24.5