-
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
-
how about a map<std::string, int>
Code:
#include <map>
std::map <std::string, int> Counter;
Counter[curr->word]++;
-
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
-
makes no sence at all - your curr is not initialized