answersLogoWhite

0

#include<iostream>

#include<list>

struct item

{

item(const char ch):chr(ch), count(1){}

char chr;

size_t count;

};

int main()

{

const size_t size=50;

size_t idx;

std::list<item> freq;

std::list<item>::iterator iter;

std::string test;

for(idx=0; idx<size; ++idx)

test.push_back('a'+rand()%26);

for(idx=0; idx<size; ++idx)

{

for(iter=freq.begin(); iter!=freq.end() && (*iter).chr!=test[idx]; ++iter);

if( iter!=freq.end() )

++(*iter).count;

else

freq.push_back(item(test[idx]));

}

std::cout<<"Frequency table of the string:\n""<<test.c_str()<<""\n"<<std::endl;

for(iter=freq.begin(); iter!=freq.end(); ++iter)

{

item& itm=*iter;

std::cout<<itm.chr<<" = "<<itm.count<<std::endl;

}

std::cout<<std::endl;

}

User Avatar

Wiki User

11y ago

What else can I help you with?

Related Questions

Write a c program for alphabetical order?

int main (void) { puts ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); return 0; }


How do you write a c program to read two character from keyboard nd sot them in alphabetical order?

Every character in C++ is basically belongs to short. You can convert entered characters to short, compare their values and according to the values sort them in alphabetical order.


Write a c program for creating a virus?

a c program for creat a virus


Where do we write main function in a c program?

Into the source program.


Write a c program to find Volume and surface area of cube?

Write a c program to compute the surface area and volume of a cube


How do you write a c program to analysis a circuit?

There is no need to write a C program for circuit analysis; there are lots of packages out there that already do that (for example, Spice).


A C program using dynamic memory allocation to sort n names in ascending order?

Writing a C program that uses dynamic memory allocation to sort names in ascending order is a typical computer science assignment. To write this program, you must be in UNIX.


How do you write a C program to check whether the number is odd or even Ps-using DEV complier?

To write a C program to determine if something is odd or even you need to be a programmer. To write a program in C is complicate and only done by programmers.


How do you write socket program in c?

For first find an example program.


How do you write a program in embedded c?

Use a text-editor program.


How do you write a program to read set of numbers using by an array and display the ascending order of the given input numbers?

To write a C++ program to display the student details using class and array of object.


What is the program to write route cipher?

c#