User Tools

Site Tools


haas:fall2018:data:projects:sln1

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
haas:fall2018:data:projects:sln1 [2017/08/27 20:41] – external edit 127.0.0.1haas:fall2018:data:projects:sln1 [2018/09/06 14:20] (current) – [node library] wedge
Line 3: Line 3:
 <WRAP><fs 150%>CSCS2320 Data Structures</fs></WRAP> <WRAP><fs 150%>CSCS2320 Data Structures</fs></WRAP>
 </WRAP> </WRAP>
- 
-~~TOC~~ 
  
 ======Project: Singly Linked Nodes (sln1)====== ======Project: Singly Linked Nodes (sln1)======
Line 132: Line 130:
 We will use struct to package its contents. We will use struct to package its contents.
  
-What is **in** the node? Again, this answer depends on our particular needs. For now, lacking any specific application, let us put some value in our node (we'll call it **contents**, as our node //contains// a value).+What is **in** the node? Again, this answer depends on our particular needs. For now, lacking any specific application, let us put some value in our node (we'll call it **info**, as our node //contains// a value of information).
  
 The node, to make it practical and useful, also needs the ability to reference other nodes. Pointers are they key for referencing other variables (via memory address storage and dereferencing), so our simple node will also contain a pointer. The node, to make it practical and useful, also needs the ability to reference other nodes. Pointers are they key for referencing other variables (via memory address storage and dereferencing), so our simple node will also contain a pointer.
Line 142: Line 140:
 <code c> <code c>
 struct node { struct node {
-    char contents+    char info
-    struct node *to;+    struct node *right;
 }; };
 </code> </code>
Line 151: Line 149:
 <code c> <code c>
 struct node { struct node {
-    char contents+    char info
-    struct node *to;+    struct node *right;
 }; };
 typedef struct node Node; typedef struct node Node;
Line 160: Line 158:
  
 <code c> <code c>
-struct node *first;+struct node *first = NULL;
 </code> </code>
  
Line 166: Line 164:
  
 <code c> <code c>
-Node *first;+Node *first = NULL;
 </code> </code>
  
Line 187: Line 185:
 <code c> <code c>
 // to assign // to assign
-first -> contents = 12; // first is a pointer to a struct, so we use the structure pointer arrow+first -> info = 12; // first is a pointer to a struct, so we use the structure pointer arrow
  
 // to retrieve // to retrieve
-printf("first's value is %hhd\n", first -> contents);+printf("first's value is %hhd\n", first -> info);
  
-// dealing with the next node, the 'there' pointer- set it to an initial sane value +// dealing with the next node, the 'right' pointer- set it to an initial sane value 
-first -> to = NULL;+first -> right = NULL;
 </code> </code>
  
Line 210: Line 208:
  
 <code c> <code c>
-first -> to = (Node *) malloc (sizeof(Node)); +first -> right = (Node *) malloc (sizeof(Node)); 
-first -> to -> contents = 37; +first -> right -> info = 37; 
-first -> to -> to = NULL;+first -> right -> right = NULL;
 </code> </code>
  
Line 222: Line 220:
 Since we need to keep a placeholder on our allocated memory, **first** is intended to be a more or less immovable aspect of our list (it is our link to everything- we don't want to adjust it unless we absolutely need to). Since we need to keep a placeholder on our allocated memory, **first** is intended to be a more or less immovable aspect of our list (it is our link to everything- we don't want to adjust it unless we absolutely need to).
  
-You may be noticing the potential for some very long code about to happen (what if we wanted to add a third node... those there's would become there -> there, and so on). But there's a way to keep it simple (but ambiguous, at least without an updated diagram)... and that is to just use another variable, whose job is to be more of a temporary placeholder. We shall call it **tmp**.+You may be noticing the potential for some very long code about to happen (what if we wanted to add a third node... those there's would become right -> right, and so on). But there's a way to keep it simple (but ambiguous, at least without an updated diagram)... and that is to just use another variable, whose job is to be more of a temporary placeholder. We shall call it **tmp**.
  
 Here is that same node construction logic, redone using an additional **tmp** node pointer, and also adding in a third node (containing the value 8): Here is that same node construction logic, redone using an additional **tmp** node pointer, and also adding in a third node (containing the value 8):
  
 <code> <code>
-Node *first, *tmp = NULL;+Node *first = NULL, *tmp = NULL;
  
 first = (Node *) malloc (sizeof(Node)); first = (Node *) malloc (sizeof(Node));
 tmp = first; tmp = first;
  
-tmp -> contents = 12; +tmp -> info = 12; 
-tmp -> to = NULL;+tmp -> right = NULL;
  
-tmp -> to = (Node *) malloc (sizeof(Node)); +tmp -> right = (Node *) malloc (sizeof(Node)); 
-tmp = tmp -> to;+tmp = tmp -> right;
  
-tmp -> contents = 37; +tmp -> info = 37; 
-tmp -> to = NULL;+tmp -> right = NULL;
  
-tmp -> to = (Node *) malloc (sizeof(Node)); +tmp -> right = (Node *) malloc (sizeof(Node)); 
-tmp = tmp -> to;+tmp = tmp -> right;
  
-tmp -> contents = 8; +tmp -> info = 8; 
-tmp -> to = NULL;+tmp -> right = NULL;
 </code> </code>
  
Line 259: Line 257:
 <cli> <cli>
 lab46:~/src/data$ grabit data sln1 lab46:~/src/data$ grabit data sln1
-make: Entering directory '/var/public/fall2017/data/sln1' +make: Entering directory '/var/public/SEMESTER/data/sln1' 
-Commencing copy process for fall2017 data project sln1+Commencing copy process for SEMESTER data project sln1
  -> Creating project sln1 directory tree           ... OK  -> Creating project sln1 directory tree           ... OK
  -> Copying sln1 project files                     ... OK  -> Copying sln1 project files                     ... OK
Line 268: Line 266:
 *** Copy Complete! You may now switch to the '/home/USER/src/data/sln1' directory *** Copy Complete! You may now switch to the '/home/USER/src/data/sln1' directory
  
-make: Leaving directory '/var/public/fall2017/data/sln1'+make: Leaving directory '/var/public/SEMESTER/data/sln1'
 lab46:~/src/data$  lab46:~/src/data$ 
 </cli> </cli>
Line 284: Line 282:
  
 **NOTE:** If you move **sln1** to a different directory, you **MUST** retain the **sln1** name for the directory-- there's a lot of administrative logic helping to make our lives easier that is based on that specific name for the project directory. **NOTE:** If you move **sln1** to a different directory, you **MUST** retain the **sln1** name for the directory-- there's a lot of administrative logic helping to make our lives easier that is based on that specific name for the project directory.
 +
 ====Overview==== ====Overview====
 You'll see various files and directories located here (one regular file, **Makefile**, and 6 directories). The directory structure (note, not all these directories may yet be present) for the project is as follows: You'll see various files and directories located here (one regular file, **Makefile**, and 6 directories). The directory structure (note, not all these directories may yet be present) for the project is as follows:
Line 399: Line 398:
  
 As such, it is most advisable to have completed work on **sln1** and submitted it before upgrading to the **sll0** project, so any work you've done will be immediately available to build upon in the next project (the projects will be comprehensive to one another-- **sll0** will rely on work completed in **sln1**, **sll1** (the project following **sll0**) will rely on the work done in **sll0**, etc.). As such, it is most advisable to have completed work on **sln1** and submitted it before upgrading to the **sll0** project, so any work you've done will be immediately available to build upon in the next project (the projects will be comprehensive to one another-- **sll0** will rely on work completed in **sln1**, **sll1** (the project following **sll0**) will rely on the work done in **sll0**, etc.).
 +
 ====error reporting==== ====error reporting====
 To facilitate debugging and correction of errors and warnings in your code at compile time, such compiler messages will be redirected to a text file called **errors** in the base of the project directory. To facilitate debugging and correction of errors and warnings in your code at compile time, such compiler messages will be redirected to a text file called **errors** in the base of the project directory.
Line 405: Line 405:
  
 With each new project build, this file is overwritten, so you always have the most up-to-date version of compile-time information. With each new project build, this file is overwritten, so you always have the most up-to-date version of compile-time information.
 +
 =====Project Task===== =====Project Task=====
  
Line 445: Line 446:
 This is your API for the node library. In order to use the node library three things need to happen: This is your API for the node library. In order to use the node library three things need to happen:
  
-  * you must **#include "node.h"** (generally already done you in this project)+  * you must **#include "node.h"** (generally already done for you in this project)
   * you must link against **lib/libnode.a** (the Makefiles will take care of this for you)   * you must link against **lib/libnode.a** (the Makefiles will take care of this for you)
   * you must call the functions providing the appropriate arguments and handling the return values   * you must call the functions providing the appropriate arguments and handling the return values
Line 456: Line 457:
  
 Again, same details apply here, only the Makefile system automates the library linking. All we have to do is **#include** the appropriate files. Again, same details apply here, only the Makefile system automates the library linking. All we have to do is **#include** the appropriate files.
 +
 ====Node application programs==== ====Node application programs====
 Upon successful implementation of the node library, take a look in **app/node/**, which will have (among others) the following files: Upon successful implementation of the node library, take a look in **app/node/**, which will have (among others) the following files:
Line 619: Line 621:
  
 =====Submission===== =====Submission=====
-{{page>haas:fall2016:common:submitblurb#DATA&noheader&nofooter}}+{{page>haas:fall2018:common:submitblurb#DATA&noheader&nofooter}}
  
haas/fall2018/data/projects/sln1.1503866496.txt.gz · Last modified: 2017/08/27 20:41 by 127.0.0.1