Project 3 - Directory Trees


Due : 11:59pm, 29 July

Write a program to read a multi-level directory into memory and allow the user to search for a directory/file with a given name.

A popular use for such techniques was in the days of DOS, when many programs (NCD, QCD, etc.) were written to change to a directory multiple levels deep without specifying all the intermediate names. These days such techniques are used mainly for searching for files.

Your program must store the information about each directory in a linked list. Any node within the linked list should correspond to a single entry in a typical directory, with pointers to next nodes and further linked lists to handle subdirectories. Ultimately, the structure should resemble that of a general tree.

Using a node structure similar to the following one will accomplish this goal :

class Node
{
public:
   Node ( char *s );
   virtual ~Node ();
   char *data;
   Node *next, *directory;
};

Furthermore, the main class representing the data structure may include the following structure :

class Directory
{
public:
   Node *head;
   Directory ( char *dir );
   ~Directory ();
   Node *Build ( char *dir );
   void Print ();
   Node *Find ( char *s, char *output );
};

Write the following methods into your data structure :

Platform-independent source code for generating a directory tree under GCC/VC is provided, along with a demonstration on how to use this code. Include these files as appropriate. You may modify the files as you wish.

Requirements (Contents of submission)

Files

  1. dir.h
  2. dir.cc
  3. testdir.cc

Excerpts from my test program output...

File Listing:

---proj3
------testdir
------testdir.o
------dir.o
------dir.h
------Makefile~
------main.cc
---testspace
------test.cc
------Makefile
---hw5
------hw5.cc
------Makefile
---proj2
------output
------main.cc~
------Makefile~
------Makefile
---proj1
------proj1
------Makefile

Search:

Searching for [Makefile] : proj3/Makefile
Searching for [main.cc] : proj3/main.cc
Searching for [test.cc] : testspace/test.cc
Searching for [dir.o] : proj3/dir.o

Solution


Last updated : 2 August 1999 4:36pm