Hi I'm using the Pascal language and I need help with the following problem. You need to find the most common word read in by a user of arbitrary length and then display the amount of times its found in the input. I placed all the words into a linked list without hassle but the problem is I don't know how to count the repeated words in the linked list. Can someone here help me?
P.S. It has to be a linked list, but since I'm very new to the linked list data structure, if you could explain what you did, I'd appreciate it.
uses crt; type nodePointer = ^node; node = record word : string; next : nodePointer; end; list = nodePointer; var wordlist:list; words :nodePointer; newword :nodePointer; input : string; i : integer; position:integer; cut :string; begin clrscr; new(wordlist); wordlist:=nil; write('Enter a sentence:'); readln(input); input:=input+' '; for i:=1 to length(input) do begin if input[i]=' ' then begin position:=pos(input[i],input); cut:=copy(input,1,position-1); delete(input,1,position); new(newword); newword^.word := cut; newword^.next := wordlist; wordlist := newword; end; end; words:=wordlist; while words <> nil do begin write(words^.word); words := words^.next; end; end.
Edited by havoc433: n/a