Thread: Clueless about linked list

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    17

    Clueless about linked list

    Im supposed to make a program that reads an input file and outputs the number of times a certain work appears. i did it using strcmp but he wants it using linked lists. i dont see how this is possible. if you are storing values how can you count them?

  2. #2
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    maybe you check for a space and then compare the word with the actual word.

    im sorry if that's not what you want, i'm not to good with LLs
    -

  3. #3
    Unregistered
    Guest
    Are you counting the number of occurences of every word in the file, or are you taking only one specific word and counting the number of occurences in the file?

  4. #4
    jaideep
    Guest
    create a list as
    class list
    {
    string str;
    list *next;
    }start,last;
    while reading the file store the words in the list .
    traverse the list and compare with the word u need to check.

  5. #5
    Unregistered
    Guest
    to count the fequencey of every word in the file try creating a node class that has two data members and a pointer. One data member holds a string (read word) and the other is an integer counter initialized to 0.

    create a list class that has an add to end function.

    isolate a word from the file in a string. Compare the word with the string in each node. If the word is a match increment the old nodes counter by one but don't add the word to the list. If the word is not present in the list, create a new node, store the word in the string of the node and add the node to the end of the list. Repeat this for every word in the file. When all done print out the list of words in sequence with the associated counter value to display all the words used and with what frequency.


    The same process can be used to determine how many times a given word occurs in the file if you wish. After reading in the entire file just search the list for the word you are looking for. If the word is found display the counter value that it is associated with. If the word isn't found, so indicate. You can check every word in a dictionary that way if you want. Alternatively, if all you want to know is how many times a given word appears then just read in each word from the file one word at a time comparing the given word to the word read in. However, if you want to search for more than one word you have to run the program more than once if you do it this way. The other way you can do multiple searches during the same run of the program.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Following CTools
    By EstateMatt in forum C Programming
    Replies: 5
    Last Post: 06-26-2008, 10:10 AM
  2. Reverse function for linked list
    By Brigs76 in forum C++ Programming
    Replies: 1
    Last Post: 10-25-2006, 10:01 AM
  3. How can I traverse a huffman tree
    By carrja99 in forum C++ Programming
    Replies: 3
    Last Post: 04-28-2003, 05:46 PM
  4. Template Class for Linked List
    By pecymanski in forum C++ Programming
    Replies: 2
    Last Post: 12-04-2001, 09:07 PM
  5. singly linked list
    By clarinetster in forum C Programming
    Replies: 2
    Last Post: 08-26-2001, 10:21 PM