Hey, in my first year at uni and I have this exercise which I don't have a clue about.
Basically I have a programme that reads characters typed in by the user and once the squence is terminated by a '.', the programme returns the number of times each character appeared in the sequence.
It uses linked lists to achieve this, adding a character to a list and each time that character is rea, a counter in the record of that character is incremeted by 1.
Pretty simple stuff, it works and everything, even tho the coding is crap.
Now here is my problem, the next exercise says to
Now an ADT I think I'm fine with....but what the hell is this 'bag of characters' about do you know?
Any help would me much appreciated.
Basically I have a programme that reads characters typed in by the user and once the squence is terminated by a '.', the programme returns the number of times each character appeared in the sequence.
It uses linked lists to achieve this, adding a character to a list and each time that character is rea, a counter in the record of that character is incremeted by 1.
Pretty simple stuff, it works and everything, even tho the coding is crap.
Code:
with Ada.Text_IO, Ada.Integer_Text_IO;
procedure countletters is
type wordlist;
type wordlist_Ptr is access wordlist;
type wordlist is
record
letter: character;
value: integer;
Next: wordlist_ptr;
end record;
list : wordlist_Ptr := null;
letter : character;
procedure lettercount(c : in character; l: in out wordlist_Ptr) is
begin
if l = null then
l := new wordlist'(letter=>c, value=>1, Next=>null);
elsif l.all.letter = c then
l.all.value := l.all.value+1;
else
lettercount(c=>c, l=>l.all.Next);
end if;
end lettercount;
begin
ada.text_io.put("Please enter a string of characters followed by a '.': ");
ada.text_io.get(letter);
while letter /= '.' loop
lettercount(letter, list);
ada.text_io.get(letter);
end loop;
while list /=null loop
ada.text_io.put(list.all.letter);
ada.text_io.put(" ");
ada.integer_text_io.put(list.all.value);
list := list.all.Next;
ada.text_io.put_line(" ");
end loop;
end countletters;
Now here is my problem, the next exercise says to
Modularise your solution to the problem of subsubsection 4.1.1 by implementing an
ADT for the abstract notion of a bag of characters as a linked list.
Now an ADT I think I'm fine with....but what the hell is this 'bag of characters' about do you know?
Any help would me much appreciated.