User Tools

Site Tools


notes:data:fall2023:projects:ttb1

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
notes:data:fall2023:projects:ttb1 [2023/09/16 20:46] – [REMOVING A NODE FROM THE LIST] jwielandnotes:data:fall2023:projects:ttb1 [2023/09/16 20:50] (current) – [REMOVING A NODE FROM THE LIST] jwieland
Line 69: Line 69:
 =====REMOVING A NODE FROM THE LIST===== =====REMOVING A NODE FROM THE LIST=====
  
-One of the ways to delete a specific Node from a linked list is to create a function that searches for the node by its properties (e.g. x, and y) and then removes it. the psudo-code would look something like this.+One of the ways to delete a specific Node from a linked list is to create a function that searches for the node by its properties (e.g. x, and y) and then removes it. The psudo-code would look something like this.
  
 <code c> <code c>
-  void deleteBrick(Brick** start-of-list, int x, int y) { +  deleteNode(Node** start-of-list, int x, int y) { 
-  Brick* current =*start-of-list; +  Node* current =*start-of-list; 
-  Brick* previous= NULL;+  Node* previous= NULL;
   while(current!=NULL){   while(current!=NULL){
     if (current_node->x == x && current_node->y == y) {     if (current_node->x == x && current_node->y == y) {
       if(previous==NULL){       if(previous==NULL){
-        node we want to delete from the list is the first node in the list+        //node we want to delete from the list is the first node in the list
         *start-of-list =current->next;         *start-of-list =current->next;
       } else{       } else{
-        set the previous node's pointer to the current node's pointer+        //set the previous node's pointer to the current node's pointer
       }       }
       free(current)       free(current)
Line 92: Line 92:
   }   }
 </code> </code>
 +
 +In essence we are itterating through the different nodes, and checking if they are the node we want to delete. Make sure to have a catch case for the first node in the list.
 ====AT THE START OF LIST==== ====AT THE START OF LIST====
  
notes/data/fall2023/projects/ttb1.1694897195.txt.gz · Last modified: 2023/09/16 20:46 by jwieland