ANSWERS: 1
  • That depends a little on what form your data takes. The simplest case is if you have a collection of small valued integers in the range 0..N-1 to find the histogram of. Create an array int count[N]; Ensure each element in the array is zero. For each input integer item, ++count[item]; Print out the array, e.g. for(item=0;item<N;++item) printf("item %d, frequency %d n",item,count[item]); If you have more complex items like English words in a book to find the histogram of, you need a data structure with elements containing an item and a count. Search the data structure for item and increment its count. If it's not there, add it as a new item with count one. There isn't space here to go into various data structures and algorithms. Below find a link which includes an implementation of a linked list and how to search through it: http://www.cprogramming.com/tutorial/lesson15.html

Copyright 2023, Wired Ivy, LLC

Answerbag | Terms of Service | Privacy Policy