cs31 lecture 17

Stack list graph using adjacency matrix

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: is destroyed when the E.g., function exits function x Arrays are standard variables We can use references, have global arrays, put them in We namespaces, etc. namespaces, x The size of an array is set at its declaration It will not automatically increase when trying to “add” elements The program will crash if trying to access an element not in the The 100 Some observations on arrays x You cannot mix different types for the elements (but You techniques exist to overcome this: structs/unions)
 techniques x You cannot recover the size of the array from the variable You associated to it: only the declaration contains its size associated x The size of an array can be determined at run-time (C99)
 int main()
 { int a; std::cin >> a; int int array[a]; int } 101 Multidimensional arrays x Case 1: a multidimensional array is a 1-d array with Case multiple ways to index it multiple Think about a 2-d array being flattened x Case 2: a multidimensional array is an array of array Think about an array storing addresses of 1-d arrays x Example: Example: int a[10][10]; // a contiguous region of 100 elements in memory int char c[100][10][100]; char 102 Summary on arrays x Arrays are key to real data manipulation x Now, you can start implementing your data structures! Stack List Graph (using adjacency matrix representation)
 … x When the array needs to live after a function has finished, When use dynamic allocation use x In other cases, use static allocation, and pass it i...
View Full Document

Ask a homework question - tutors are online