Thread: structures/linked lists

  1. #1
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    Question structures/linked lists

    Can you delete an intire node that is a structure record, or do you have to delete each individual piece of data?

    Code:
    linklist::~linklist()
    {
        link *current;
    	current = head->next;
    	while (current != NULL)  
    		  {
                    x++;
    		   cout << "delete node " << head->link[x] << endl;
    		   delete head;
    		   head = current;
    		   current = current->next;
    		  }
    	cout << "Deleting last node " << head->link[x] << endl;
    	delete head;
    }
    I declared link as a structure storing names and personal data. It doesn't like the fact that I attempt to delete an entire record at once. As far as what I've learned in class up to this point is that a node can contain any object you want. So if I can delete data in a node, why can I not delete an entire record? I get the below error when trying to compile.

    (43): error C2273: 'function-style cast' : illegal as right side of '->' operator
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Code:
     cout << "delete node " << head->link[x] << endl;
    So you have a type link and you also have an array of something named link inside your list?
    What you seem to be doing is something like this:
    Code:
    int int[10];
    cout<<int[1];
    I think you have a problem with your logic?
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    Arrow structure

    It is more like a structure record.

    e.g. link[x].fname;

    Instead of deleting each individual peice of data I want to kill the node and the structure record with...

    delete link[x];

    or in this instance since head is pointing to link[x] the record, I would just delete head.

    [Edit]
    Does anybody have a syntax example of adding an entire structure record to a node?
    [\Edit]
    Last edited by xviddivxoggmp3; 09-27-2003 at 10:51 PM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  4. #4
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    You have to delete everything yourself. That being said, I didn;t really try to 'grok' your data structure so I won't be too specific. The most common approach to automating it is by using containers that delete their internal data when they themselves are being destroyed. This ensures that however far up the chain something is deleted, everything else gets taken care of as well.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  5. #5
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    Do you mean I will have to create the new node and input each individual piece of data in to the node and to delete each individual piece of data as well.

    And I'm deducting that I can not input data into my structure first and then input each individual record into seperate nodes.

    So can I have multple peices of data in one node?

    Code:
     
    		link* newlink = new link;  //create node and points newlink to new node        
    		newlink->fname = fname;         //puts name into data field    
    		newlink->lname = lname;
    		newlink->next = head;	//gives new node null or addy to next node
    [Edit]
    I guess my real question would be can I have a pointer for the new node point at multiple locations, or like what was mentioned before how would I create a container that would encapsulate multiple iteams of data for a linked node?
    (e.g. membership registry: first name, last name, ssnumber, etc.)
    Why can I not use a structure record as a container?
    [/Edit]
    Last edited by xviddivxoggmp3; 09-27-2003 at 11:31 PM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help creating lists of pointers
    By The_Kingpin in forum C Programming
    Replies: 2
    Last Post: 12-11-2004, 08:10 PM
  2. Question about Linked lists of lists
    By hear_no_evil in forum C Programming
    Replies: 2
    Last Post: 11-08-2004, 02:49 AM
  3. Linked Lists 101
    By The Brain in forum C++ Programming
    Replies: 5
    Last Post: 07-24-2004, 04:32 PM
  4. Map file formats and linked lists
    By Spitball in forum Game Programming
    Replies: 2
    Last Post: 03-04-2004, 11:32 PM
  5. need help w/ linked lists
    By MKashlev in forum C++ Programming
    Replies: 11
    Last Post: 08-05-2002, 08:57 PM