Thread: Linked lists

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    56

    Linked lists

    oky the problem is that i need to read a passage and store the words in a linked list.i also need to check and see which words repeat and keep count how muhc times the word is repeted.i have already done the progrm to read the passage out.im leaving all words lower case to make things simpler.HOWEVER i dont know how to ceck to see if the word was repeated. cna anyone provide some guidlines i can follow to code something like that?
    i was thinking something like sthis but its not working
    Code:
    int search(Nodeptr top){
        
        Nodeptr curr;
      
        int x=1;
        while(curr!=NULL){curr=top;
        while(top!=NULL){
                         if(strcmp(curr->word,top->word)==0){curr->count=x++;}
                        top=top->next;
                         }
    }
     
        
    }
    tell me if that makes any sense at all,or if not waht should i try to do thnx

  2. #2
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    how about a map<std::string, int>

    Code:
    #include <map>
    
    std::map <std::string, int> Counter;
    
    Counter[curr->word]++;

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    56
    well i made a struct for the nodeptr
    Code:
    typedef struct node{
                        char word[20];
                        int count;
                        struct node *next;
                        }Node,*Nodeptr;
    so i was trying to store the increments in that mem vaiable count

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    while(curr!=NULL)
    makes no sence at all - your curr is not initialized
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Singly Linked Lists: Clarification Needed
    By jedispy in forum C++ Programming
    Replies: 4
    Last Post: 12-14-2006, 05:30 PM
  2. Linked Lists 101
    By The Brain in forum C++ Programming
    Replies: 5
    Last Post: 07-24-2004, 04:32 PM
  3. Map file formats and linked lists
    By Spitball in forum Game Programming
    Replies: 2
    Last Post: 03-04-2004, 11:32 PM
  4. need help w/ linked lists
    By MKashlev in forum C++ Programming
    Replies: 11
    Last Post: 08-05-2002, 08:57 PM
  5. doubly linked lists
    By qwertiop in forum C++ Programming
    Replies: 3
    Last Post: 10-03-2001, 06:25 PM