Program to find equivalence classes Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan...

12
Program to find equivalence classes Instructor : Prof. Jyh-Shing Roger Jang Designer Shao-Huan Wang The ideas are reference to the textbook “Fundamentals of Data Structures in C “ .

Transcript of Program to find equivalence classes Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan...

Page 1: Program to find equivalence classes Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan Wang The ideas are reference to the textbook “Fundamentals.

Program to find equivalence classes

Instructor : Prof. Jyh-Shing Roger Jang

Designer : Shao-Huan WangThe ideas are reference to the textbook “Fundamentals of Data Structures in C “ .

Page 2: Program to find equivalence classes Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan Wang The ideas are reference to the textbook “Fundamentals.

Program to find equivalence classes

0 1 2 3 4 5 6 7 8 9 10 11

First, we input many pair of numbers and

4 0

(0,4)

13 10 69 8

(3,1)(6,10)(8,9)

Page 3: Program to find equivalence classes Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan Wang The ideas are reference to the textbook “Fundamentals.

4 211 007 961 108

Program to find equivalence classes

0 1 2 3 4 5 6 7 8 9 10 11

3 684

(7,4)(6,8)(3,5)(2,11)(11,0)

3511

First, we input many pair of numbers and

(0,4)(3,1)(6,10)(8,9)

And add the number from the bottom if the space isn’t empty

Page 4: Program to find equivalence classes Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan Wang The ideas are reference to the textbook “Fundamentals.

4 20 91 10

Program to find equivalence classes

0 1 2 3 4 5 6 7 8 9 10 11

3 68431111 5 7 8 6 0

From 0 to 11 if the number is unused, print “New class”,print and mark the number become used.

stack

Print:New class: 0

And from its link to find another number, if the linked number also link another number,push the linked number to stack.

11 4

Then, from the top of stack to find the same class number.

Page 5: Program to find equivalence classes Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan Wang The ideas are reference to the textbook “Fundamentals.

4

20 91 10

Program to find equivalence classes

0 1 2 3 4 5 6 7 8 9 10 11

3 684311 5 7 8 6 0

From 0 to 11 if the number is unused, print “New class”,print and mark the number become used.

Print:New class: 0

And from its link to find another number, if the linked number also link another number,push the linked number to stack.

11 4

Then, from the top of stack to find the same class number.

7

11

stack

If the number is already used, skip it.

Page 6: Program to find equivalence classes Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan Wang The ideas are reference to the textbook “Fundamentals.

7

291 10

Program to find equivalence classes

0 1 2 3 4 5 6 7 8 9 10 11

3 684311 5 8 6 0

From 0 to 11 if the number is unused, print “New class”,print and mark the number become used.

Print:New class: 0

And from its link to find another number, if the linked number also link another number,push the linked number to stack.

11 4

Then, from the top of stack to find the same class number.

7

If the number is already used, skip it.

11

stack

2

Page 7: Program to find equivalence classes Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan Wang The ideas are reference to the textbook “Fundamentals.

2

91 10

Program to find equivalence classes

0 1 2 3 4 5 6 7 8 9 10 11

3 68311 5 8 6

From 0 to 11 if the number is unused, print “New class”,print and mark the number become used.

Print:New class: 0

And from its link to find another number, if the linked number also link another number,push the linked number to stack.

11 4

Then, from the top of stack to find the same class number.

7

If the number is already used, skip it.

stack

2New class: 13

Page 8: Program to find equivalence classes Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan Wang The ideas are reference to the textbook “Fundamentals.

91 10

Program to find equivalence classes

0 1 2 3 4 5 6 7 8 9 10 11

6835 8 6

From 0 to 11 if the number is unused, print “New class”,print and mark the number become used.

Print:New class: 0

And from its link to find another number, if the linked number also link another number,push the linked number to stack.

11 4

Then, from the top of stack to find the same class number.

7

If the number is already used, skip it.

2New class: 13

3

stack

5

Page 9: Program to find equivalence classes Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan Wang The ideas are reference to the textbook “Fundamentals.

910

Program to find equivalence classes

0 1 2 3 4 5 6 7 8 9 10 11

683

5

8 6

From 0 to 11 if the number is unused, print “New class”,print and mark the number become used.

Print:New class: 0

And from its link to find another number, if the linked number also link another number,push the linked number to stack.

11 4

Then, from the top of stack to find the same class number.

7

If the number is already used, skip it.

2New class: 13

stack

5New class: 6

Page 10: Program to find equivalence classes Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan Wang The ideas are reference to the textbook “Fundamentals.

910

Program to find equivalence classes

0 1 2 3 4 5 6 7 8 9 10 11

688 6

From 0 to 11 if the number is unused, print “New class”,print and mark the number become used.

Print:New class: 0

And from its link to find another number, if the linked number also link another number,push the linked number to stack.

11 4

Then, from the top of stack to find the same class number.

7

If the number is already used, skip it.

2New class: 13

stack

5New class: 68 10

Page 11: Program to find equivalence classes Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan Wang The ideas are reference to the textbook “Fundamentals.

9

10

Program to find equivalence classes

0 1 2 3 4 5 6 7 8 9 10 11

68

8

6

From 0 to 11 if the number is unused, print “New class”,print and mark the number become used.

Print:New class: 0

And from its link to find another number, if the linked number also link another number,push the linked number to stack.

11 4

Then, from the top of stack to find the same class number.

7

If the number is already used, skip it.

2New class: 13

stack

5New class: 68 10 9

Page 12: Program to find equivalence classes Instructor : Prof. Jyh-Shing Roger Jang Designer : Shao-Huan Wang The ideas are reference to the textbook “Fundamentals.

9

Program to find equivalence classes

0 1 2 3 4 5 6 7 8 9 10 11

8

From 0 to 11 if the number is unused, print “New class”,print and mark the number become used.

Print:New class: 0

And from its link to find another number, if the linked number also link another number,push the linked number to stack.

11 4

Then, from the top of stack to find the same class number.

7

If the number is already used, skip it.

2New class: 13

stack

5New class: 68 10 9