Help me!!!

To me, it's extremely difficult(over 500 points)-sorry for that.
Please answer my question as soon as possible. Thank you!!!

I'm a pupil( 14 years old) who have a little experience in using pascal. And it's difficult for me to have to write a program by using pascal.

My problem is "closest pair in the plane problem". Using 2 algorithms: "divide and conquer" and "sweep the plane".  Could you give me source code with a complete program.

To me, i will have to try my best to understand algorithms and your code.
Please answer my question as soon as possible. Thank you very much.!!!!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Since this seems like a homework question you have to post some code here that we can look at it and eventually correct your errors if there are some.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
quacauAuthor Commented:
{i wrote this based on Sedgewick'Book.,i feel very difficult, i understood algorithms, but this program can't run. Please help me as soon as possible, My experts, my brother, I'll vote 500 points for you, all of you.. after i finish "divide and conquer", " i will write this with algorithm:"a plane sweep, and sorry for bothering you."}

{ because i'm 14 years old pupil, please explain clearly, especially, this program seems to be correct but it can't run.}

{and i'd like to know how to use time function in pascal to display time of algorithm, when i use a large set of points, thank you}

program closest_pair; { divide and conquer}
uses crt,dos,overlay;

point = record
x: real;
y: real;
link = ^node;
node = record
p: point;
next: link;

keeptrack: link;            { i'll use it to keep track of my list}
list,head: link;                 {i'll use list to input a set of points}
first: link;
minresult: real;
closest1,closest2: point;         {current closest pair, they can be updated}
sortx: boolean;               {sortx = false -> sort y}
n,v: integer;                 {n points}

function merge(list1,list2 :link) : link;  
var list12: link;
addlist :boolean;
list12:= keeptrack ;   {it seems to be unlimited loop, really difficult or i have a wrong list that declares in the main program }
if sortx = true then addlist:= list1^.p.x < list2^.p.x
          else addlist:= list1^.p.y < list2^.p.y ;
          if addlist then   begin list12^.next := list1; list12:= list1; list1 := list1^.next end
                  else begin list12^.next := list2; list12:=list2; list2 := list2^.next end
until list12 = keeptrack;
merge := keeptrack^.next;
keeptrack^.next := keeptrack;

procedure check(p1,p2: point);         { it's easy, i got it}
var distance : real;
if (p1.y <> keeptrack^.p.y) and (p2.y<> keeptrack^.p.y) then
begin distance := sqrt((p1.x -p2.x)*(p1.x -p2.x) + (p1.y -p2.y)*(p1.y - p2.y));
if distance < minresult then
begin minresult:= distance;
      closest1:= p1;
      closest2:= p2;

function sort(c: link; n: integer):link;
var a,b: link;
    i: integer;
    middle: real;
    p1,p2,p3,p4: point;
if c^.next = keeptrack then sort:= c else
begin a := c;
      for i:= 2 to (n div 2) do c:= c^.next;
      b:= c^.next;
      c^.next := keeptrack;
if sortx = false then middle := b^.p.x;
c := merge(sort(a, n div 2), sort(b,n-(n div 2)));
sort := c;
if sortx = false then
a:= c; p1:=keeptrack^.p; p2:=keeptrack^.p; p3:= keeptrack^.p; p4:= keeptrack^.p;
if abs(a^.p.x - middle) < minresult then
   begin check(a^.p,p1);
         p1:=p2; p2:=p3; p3:=p4; p4:=a^.p;
a:= a^.next;
until a=keeptrack ;

begin          { please check this for me,do i have s mistakes}
keeptrack^.p.x:= maxint;
keeptrack^.p.y:= maxint;
writeln('how many points are there on the plane: ????');
list := nil;
for v:=1 to n do begin
first^.p.x := random(1000);
first^.p.y := random(1000);
first^.next := list;
list := first;

new(head); head^.next:= list;
minresult := maxint;
sortx:= true; head^.next:=sort(head^.next,n);
sortx:= false; head^.next:= sort(head^.next,n);

writeln(closest1.x);   { the problem is not important anymore}

quacauAuthor Commented:
This program can't work correctly, if I have a mistake list( head^.next :=list) or i have some mistakes in function merge or function sort, thank you, i'll vote 500 points for you.
quacauAuthor Commented:
Writeln( closest1.x); ( it can't display, means

 new(head); head^.next:= list;
minresult := maxint;
sortx:= true; head^.next:=sort(head^.next,n);
sortx:= false; head^.next:= sort(head^.next,n);   { implement algorithm}

have some problem, please check it for me.  Thank you...
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.