Wavelet transform And Its Applications to Image Processing - PowerPoint PPT Presentation

About This Presentation
Title:

Wavelet transform And Its Applications to Image Processing

Description:

If the size is too big, it?? a waste of memory. ... pointer of the next cat. Computer Programming and Basic ... Ask the user to determine the number of cats ... – PowerPoint PPT presentation

Number of Views:28
Avg rating:3.0/5.0
Slides: 15
Provided by: hkpu
Category:

less

Transcript and Presenter's Notes

Title: Wavelet transform And Its Applications to Image Processing


1
Writing a Good Program 8. Elementary Data
Structure
2
Computer Programming and Basic Software
Engineering
8. Elementary Data Structure
Linked Lists
  • In using array, one needs to define the size
    beforehand.
  • If the size is too big, its a waste of memory.
  • If the size is too small, it may even crash the
    system.
  • If we want the number of items in an array to be
    dynamically defined during the program execution,
    linked lists are more useful.
  • A linked list is a data structure that consists
    of a number items, with each item having a
    pointer points to the location of the next item.

3
Computer Programming and Basic Software
Engineering
8. Elementary Data Structure
Linked List
Free Store or the heap
CAT 1
CAT 499
.
0
...
CAT 0
.
.
A null pointer means the end of the list
Address of the next item
A pointer Head is kept to point to the beginning
memory location of a linked list of CAT objects
in Free Store
The Stack
Code Space
Global Name Space
4
Computer Programming and Basic Software
Engineering
8. Elementary Data Structure
Head
  • Linked lists have 3 forms
  • Singly linked
  • Doubly linked
  • Tree

0
Singly linked
Data
Head
Head
.
.
Data
Data
Data
.
.
.
.
.
.
.
.
0
0
0
0
Data
Doubly linked
Tree
0
.
.
0
0
5
Computer Programming and Basic Software
Engineering
8. Elementary Data Structure
Linked Lists - Add an item
Append an item to the end
6
Computer Programming and Basic Software
Engineering
8. Elementary Data Structure
Linked Lists - Remove an item
Remove the last item
7
Computer Programming and Basic Software
Engineering
Linked Lists - How can it be done?
8. Elementary Data Structure
include ltiostreamgt using namespace std class
CAT //Use a number CatNum to represent a
cat public CAT() pNext0 CAT()
int GetNum() const return CatNum void
SetNum(int num) CatNum num CAT
GetNext() return pNext void SetNext(CAT
pN) pNext pN private int CatNum CAT
pNext
A linked list of CAT objects is to be created
All functions implemented
Record the cat number
Record the pointer of the next cat
8
Computer Programming and Basic Software
Engineering
8. Elementary Data Structure
if n 3
CAT create(int n) //Create a linked
list CAT pH,pT,pL int i pH new CAT pL
pH pL-gtSetNum(0) for (i1 iltn i) pT
new CAT pL-gtSetNext(pT) pL
pT pL-gtSetNum(i) //pL points to last
item return pH
0
1
2
9
Computer Programming and Basic Software
Engineering
8. Elementary Data Structure
Ask the user to determine the number of cats
int main() int num CAT pHead, pTemp cout
ltlt "How many Cats " cin gtgt num pHead
create(num) pTemp pHead do cout ltlt
"Cat " ltlt pTemp-gtGetNum() ltlt endl pTemp
pTemp-gtGetNext() while (pTemp!0) return
0
As the number of CAT is dynamically determined,
we cannot use array approach (array index is not
a variable)
Call create() to create a linked list of CAT
objects
Print out all the CAT number recorded in each CAT
object
10
Computer Programming and Basic Software
Engineering
8. Elementary Data Structure
Add an item to the end
Go from head to end, then add item.
// Add an item to the end // Return the head
pointer CAT addend(CAT pH) CAT pCurr,
pPrev, pCat int j0 //CatNum to be
written pCurr pH do // find the item
pPrev pCurr j pCurr
pCurr-gtGetNext() while (pCurr !
0) // pPrev is pointing last item pCat
new CAT pPrev-gtSetNext(pCat)
pCat-gtSetNum(j) // write CatNum return pH
0
1
2
How about inserting an item somewhere inside?
11
Computer Programming and Basic Software
Engineering
8. Elementary Data Structure
Remove an item
if n 1
pH
// Remove the second item n1 // Return the head
pointer CAT remove(int n, CAT pH) CAT
pCurr, pPrev, pCat int i0 pCurr
pH do // find the item pPrev pCurr
pCurr pPrev-gtGetNext() i while
(iltn) // pCurr is pointing the deleted
item pCatpCurr-gtGetNext() pPrev-gtSetNext(pCat)
delete pCurr return pH
0
2
How about removing the first item (pointed by pH)?
0
12
Computer Programming and Basic Software
Engineering
Exercise 8.1
8. Elementary Data Structure
Redesign the program in p. 9 such that every item
contains the name of the cat, which is a string.
After creating the linked list, it will
continuously ask the user to show all items,
insert an item, delete an item in the linked
list, or quit. We need to modify the main() and
write two functions. CAT insert(int n, char
pName, CAT pHead) // int n - the insert
position in the linked list // The first item is
in position 0 // char pName - the name of the
cat to be inserted // CAT pHead - the head
pointer (initially pHead 0) // The function
should return the revised head pointer CAT
del(int n, CAT pHead) // int n - the delete
position in the linked list // CAT pHead - the
head pointer (initially pHead 0) // The
function should return the revised head pointer
13
Computer Programming and Basic Software
Engineering
8. Elementary Data Structure
Exercise 8.1 (cont)
Your program should be able to allocate or free
the memory required to implement the two
functions above. It should also check whether the
integer n is bigger than the size of the list.
14
(No Transcript)
Write a Comment
User Comments (0)
About PowerShow.com