Results 1 to 4 of 4
Thread: funtion pointer
- 12-04-2012, 09:16 PM #1
Member
- Join Date
- Dec 2012
- Posts
- 2
- Rep Power
- 0
funtion pointer
Hi everyone
i'm want write blow code in java . i have about 130 rule function .
this code has O(n) and i want change it to O(1).
i think java have Function Pointer but i don't know how dose it work !
Java Code:public Player rule0() { Deque<Integer> dTail = new ArrayDeque<Integer>(); dTail.add(1); dTail.add(2); Player result = new Player(0, 2, dTail); return result ; } public Player rule1() { Deque<Integer> dTail = new ArrayDeque<Integer>(); dTail.add(61); dTail.add(27); Player result = new Player(1, 120, dTail); return result ; } public Player getRule(int dIndex) { if (dIndex == 0) return rule0(); if(dIndex == 1) return rule1(); Player empty= new Player (); return empty ; }
-
Re: funtion pointer
True "function" pointers I think are proposed to be part of Java 1.8, but are not part of Java 1.7.
- 12-04-2012, 09:55 PM #3
Member
- Join Date
- Dec 2012
- Posts
- 2
- Rep Power
- 0
Re: funtion pointer
what dose it mean ?
java JDK 1.8?
i don't know how programming with java
- 12-05-2012, 01:31 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,546
- Rep Power
- 11
Re: funtion pointer
What you can do instead is create an interface and code your rules as an array of instances of this interface. If all your rules are void methods as in the example the interface could have a single execute() method to do the work.
(If that doesn't make sense, it time to consult a textbook! Or stick with what you have: but bear in mind that what wroks for a couple of rules might get very clumsy for 130 of them. It's not so much the O(whatever) business, it's the lack of structure and order that the object oriented design attempts to address.)
Similar Threads
-
this pointer
By janani@tcs in forum New To JavaReplies: 10Last Post: 08-22-2012, 09:40 AM -
how to resolve last funtion
By spinter in forum Advanced JavaReplies: 2Last Post: 10-28-2011, 01:35 AM -
funtion of close() method?
By hacikho in forum New To JavaReplies: 7Last Post: 10-11-2010, 01:08 AM -
A variable pointer
By tapies in forum New To JavaReplies: 13Last Post: 09-12-2008, 10:44 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks