08ArraysLarge - CMSC 106 Lecture Set #8 Set Started:...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CMSC 106 Lecture Set #8 Set Started: Wednesday, October 19, 2010 Data Structures s Holds a collection of data s several individual variables s each stores its own value s each is independent of the other s but the group can be allocated as a whole s Many Data Structures s arrays, stacks, queues s structures s linked list, tree, hash table, graph, … s Classifications s Homogeneous data structure vs Heterogeneous data structure s Statically sized or Dynamically sized s Single Unit or Linked Data Structures
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Array Indexing s C provides a special syntax for accessing cells in an array s Allocation of space for array named a: int a[5]; s This creates five int variables “named”:: a[0],a[1],a[2],a[3],a[4] s To modify contents of cell #2 to 6 and cell #1 to 74: a[2] = 6; a[1] = 74; s To use the contents of cell #2 and cell #1 : printf(“value = %d\n“,(a[1]-a[2])); s This access mechanism to the individual elements is called array indexing s In Java / C / C++, array cells are indexed beginning at 0 and going up to n-1 (n is number of cells) s Beware: start at 0! and end at one less than the size!! Square Brackets: [ ] and specifying the length s Two independent uses in C: s Array object creation int a[10]; s Array indexing a[0] s Nothing in the array or about the array to indicate
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 8

08ArraysLarge - CMSC 106 Lecture Set #8 Set Started:...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online