I can try to give you some pointers.
Basically, you should iterate over all pages, and for each page, reach a decision whether you should show it's number or not.
If you decided that you shouldn't show a certain page x, then remember that you might decide not to show page x+1 as well - in that case '...' will stand for both pages (or for some k following pages).
Pseudo code should be something like:
PROCEDURE PRINT_PAGINATION(input N = total number of pages, n = current page)
FOR i <-- 1 to N, DO
IF SHOULD_SHOW( i ), THEN
PRINT( i )
PRINT( " " ) //print 'space'
ELSE //we shouldn't show page i - now, when should we print "... " ?!?
IF NOT SHOULD_SHOW( i-1 ), THEN
PRINT( "... ")
Please try to understand why the pseudo code above will work.
You should still figure out by yourself how to write the SHOULD_SHOW function.