Graph,VecList。
Program Requirements
This program (named graph02) will perform the same functions as pa01, but will be able to use the ADT IntList OR the ADT IntVec for the data structure that stores one adjacency list.
Give your binary compiled C program the name graph02.
Your main source file should be named graph02.c.
Your source file that IMPLEMENTS the IntList ADT should be named intList.c.
Your source file that IMPLEMENTS the IntVec ADT should be named intVec.c.
The ADT header file is intVec.h, supplied in the class locker, a directory named cmps101-avg. The complete path is given in the syllabus and on the class web page and later in this handout.
Your submission will also include intList.c and intList.h, whose requirements are the same as in pa01 (ho04.txt).
In this assignment, your intList.o AND intVec.o will be tested with other students’ programs and their intList.o AND intVec.o will be tested with yours. So use the standard names in this class.
A starter intList.h is in the course locker, but by now you should have added pre- and post-conditions.
A starter intVec.h is in the course locker, but you should replace the questions with your own comments.
The file graph01.c, etc., can be used right from pa01, except that the “main” procedure will be changed to check for some command-line flags and call different procedures depending on whether the graph is stored
using IntLists or InVecs.
Thus, the loadGraph functionality will be separated if it has not been separated in an earlier assignment. See HOW TO PROCEED below for more details.
Allocating all the arrays in graph02.c makes it easier to pass them as arguments to functions in other files, without making any global arrays.
However, if you already have working code that allocates and returns an array from a different file (such as loadGraph.c), it is okay to use and build upon that code.
Aside from intList.h, intList.c, intVec.h, intVec.c, graph02.c and graph02, the names of files, functions and arrays should be understandable but do not need to be strictly the same as this handout.
Command-line Arguments
If your program receives no command-line arguments, it should print a usage message and exit.
Command-line arguments of the form “-something” are often called “flags”, and provide the means for varying the way the program runs, or varying the form of the output. (“-“ by itself denotes stdin.)
The final command-line argument is the name of the input file, and this name will not begin with a “-“ unless it is “-“ by itself.
The command-line flag “-L” instructs the program to build the (directed, unweighted) graph from the input using ADT IntList.
The command-line flag “-V” instructs the program to build the (directed, unweighted) graph from the input using ADT IntVec.
If both flags are present or neither flag is present, print an error message on stderr (use fprintf(stderr, …)) and exit with code 1.
Note that the Unix convention is that an exit code of 0 means “normal completion” and non-zero exit codes denote various errors.
The exit code of 0 is established “return 0” from main() or by calling exit(0) anywhere. Similarly, non-zero codes may be established.
If one flag is present, but the program cannot get the file name from the command line or cannot open the input file, then a non-zero exit code should be returned.
Just like pa01, input consists of a sequence of lines on “standard input” or in an ascii file (also called text file).
The line formats are as described in the text appendix for graph.c.
Part of the assignment is to create a set of useful test files on disk.
In the class locker (see below) gr01_test1.in is an example input.
Print information on stdout.
Just like pa01. See ho04.txt and related mailing list messages. What is most important is that the correct numbers
in the correct sequence appear on each line. The punctuation like commas and brackets is for human readability.
A common convention in programming languages is that lists print as [4, 5, 1] for a list whose first element is 4, etc. [] is the empty list.
For this assignment the entire list should print on a single line.
When you run graph.java you will notice that a number appears on each line BEFORE the list. That is explained in the reading material.
If the program is using the IntList ADT (-L), the adjacencies are ordered from the beginning of the list to the end.
If the program is using the IntVec ADT (-V), you want the order to be the same as it WOULD BE if -L had been specified.
Print an informative error message if the input contains a bad vertex number, outside 1,…,n, or has the wrong number of words on a line.
This is for your own protection. It is not a grading issue and submitting a lot of tests to check bad input is not asked or desired.
Example 1 input, unweighted
6 1 4 5 4 1 3 2 3 3 3 5 6 6 5 4 3 1 2
Example 2, with weights:
6 1 4 2.7 5 4 -3 1 3 0.0
The weights should be parsed to prepare for future programs, but they are not entered into the data structure for the graph.
Remember that graphs want to start on index 1, not index 0. So allocate 1 extra space in the array and start loading at 1.
Do not worry if edges are not unique. The algorithms will work anyway.
Example 2 output would look something like this:
1 [3, 4] 2 [] 3 [] 4 [] 5 [4] 6 []
Remember, the punctuation can be to taste, but the numbers should be in the same order as shown, line by line.
When running the program on a large input file remember to use “gt;” to redirect the stdout to a file. We will supply some large files.
Standard Vec Data Structure
Section 6.2 explains array doubling. There is a fairly simple C data structure to support this. This example need not be followed exactly.
1 2 3 4 5 6
|
st⁵‼䝖䱤⡥⤼ 䜯⡮⤠㱬⽡㹳ഽਢ㱬㹮′䜼⠼⥳⁰䜢⠾⤠‼♮㭳♷㭩†‼‾ⴠ䰼•⁴‾ⴻ‼䜾䱮⠠⥣‽䜢䱰⡡⥮†䝹⠾⥩䝣⡴⥹⸻㰼⼯㹰ൡ੮㰾㹢ⱳ‽‣※‼†‼‾ 䰼㰻⼼㹰ാ㰊㹰⁴†⠠⤦†⁖⸮㰠⽣㹬൬੯㱣㸩䌠⁵††と㉩⸠㱩⽳㹴൹ੰ㱥㸯൰ਾ㰍㸼䡰㩹†⁴†䱨㰠†⽡㸠൬੯䑣♭㭷♔㭴⁶⁔†㽯㱷⽬㹬൯䉳
Ⱐ⁵
㱴⽯㹥൳ਠ㱔⽈㸠൩੮㰠㉥⁷㵣∭≰㸾㱡⽬㉥㸠൯੦㰠㹥⁁と㉥†䅴⡩⤼ ‾⁖㨭㱧⽴㹳ൺਠ㱳㹮㱩㹩†ㅤ〠ㅮⵥㅧ㙴※ば㉡び㈠†䕯䄠䐴䴮䔼 䵰⁄㱔⼠㹡㱴⽩㸠൰㱳㸠䅣䰠䱷⁴†⁹Ⱜ†⁖
†⁹⁁†ⱥ⁹†⩲⸼㱰⼾㹨੮㰠㹲†††⸼ 䥰‾ⱳ‽‼⸾䐊☠㭤‾†††㱳⼽㹧൵ੴ㱴㹲††☠㬾♮㭳‽‾‾ Ᵽ‾ ††Ⱟ⁴〠㈠⸠㰠⼠㸠ഠਠ㰠㸼†Ⱐ††⁰ば㉡‽•☾㭰♡㭳䵵⸼㰯⽳㹡൮ਾ㰠㸠䴭‼†••⁄†⁰†䅬⁴♟㭥♳㭭⁹⁴⁰ ⁰ ††⸾㰍⼊㸠ഠਠ㰠㸠⁴† ⁴ぬㅥ‾‼⸾‼䤯‾‼…⁰䌻䴼㱮⽧㹮൯ੴ㰬㹣⁵⁴†›⁰‼‾⁵ⱡ⡳†⁴《ㄠ⤠†⁹††⸊㰠⼠㸠ഠਠ㰠㸠‼‾††䴠㰾⼼㹰ൡ੮㰠㹬䑡‾ⰼ⁰‾††††䴠†⸽㰢⽣㹤ਢ㰾㸊††䔠䄠䐼䵰䕲‽⁰⁹•ⱄ※※⁶†Ɱ⁴†‵Ⱟ‼‾‾ⱡ†⁃ⸯ㱳⽰㹮ാ਼㱢㸠††† †⸼㰯⽴㸾ਊ㰠㸠䤠 ⁰ⰾ⁒⸻㰠⽦㹲ഠ੭㱯㉥†㵴≡∭㹔⁈㱣⽥㉤㸼യ੨㰲㸍䄊‾††⁷⁴⁷⁹Ⱜ†Ⱪ⁷ⱳ⁴†⸾䌊⁴ⱳⱒ⁙⁄⁰䅲ⵥⸯ⁰‼⁰⁵⁴Ɐ†⁸⁴†㱩⽬㸠does not repeat that information.
The function names in the intList ADT must be as given in the intList.h starter file for pa01.
The function names in the intVec ADT must be as given in the intVec.h starter file for pa02.
These names must be spelled and capitalized as shown in that file.
Use the mouse to cut and paste, if necessary.
But try to use query-replace to find and replace all the names in one file whose spelling will change from pa01.
Use egrep or grep to find which files have list-related names.
For this program, loadGraph.c should be a separate file, although that was not required before. loadGraph.h will provide the interface.
Functions in loadGraph.c that are only called within loadGraph.c should not appear in loadGraph.h.
The loadGraph is NOT required to be an ADT, so the functions and prototypes do not need to agree with other students.
It is probably easiest to rename loadGraph() from pa01 into loadGraphL() and then make a copy of it called loadGraphV().
The logic will be very similar, but loadGraphV() will handle IntVec for the type, instead of IntList, and use different ADT functions.
Similarly, if you had printGraph() in pa01 you probably wan
- QQ:99515681
- 邮箱:99515681@qq.com
- 工作时间:8:00-21:00
- 微信:codinghelp
联系我们 - QQ: 99515681 微信:codinghelp
程序辅导网!
|