notes52

notes52 - Pointers to Functions-They represent the addres...

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

View Full Document Right Arrow Icon
Pointers to Functions -They represent the addres of a peice of code -Pointers to a function used to implement polymorphism in C: use same peice of code for arguments that have different types. Example -Sorting function for arrays no matter what type of entry. - UNIX, A file can be: file in a disk,pipe. Example Array mappers : a procedure that executes a function for every entry in array. typedef coid (*Functptr)(int a); void int Arraymapper(int *a,int n,FuncPtr func){ //call Func for every entry in array for(int i=0;i Things to consider in Lab3 Given i &ith entried you can compute addresses by void *pith = (void *)((char *)a+i*elementSize); void *pith+1 = (void *)((char *)a+(i+1)*elementSize); calling comp function int result = compFunc(pith,pith+1); Swapping (char *) temp = (char *)malloc(elementSize);
Background image of page 1

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

View Full Document Right Arrow Icon
//swap memcopy(temp,pith); memcopy(pith,pith+1); memcopy(pith+1,temp); }free(temp); Dictionaries They are data structures that map a key to some data. Examples SID - Student info name schedule etc. Abstract Data class class Dictionary{ public: virtual bool insert(KeyType key,DataType data);
Background image of page 2
virtual bool lookup(KeyType key,DataType *data); //returns in data the item that matches the key //otherwise false virtual bool remove(KeyType Key) //remove entry that matches key //false if key does not exist }; Insert Lookup Remove Array O(n) O(n) O(n) List O(n) O(n) O(n) hashTab O(1) O(1) O(1)(avg expected in all cases) AVLTree O(log n)O(log n)O(log n) Tb tree o(log n)O(log n)O(log n)
Background image of page 3

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

View Full Document Right Arrow Icon
Hash Table -Implementation of a Dictionary -There is an array of lists. The key is mapped to an index
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 16

notes52 - Pointers to Functions-They represent the addres...

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

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