如何做个链表,将平面上的点坐标存入,再读出?请大虾帮忙!

解决方案 »

  1.   

    书上有N多例子!无非就是定义一个结构:
    struct node {
      int x;
      int y;
      struct node * next;
    };然后,就是定义指针;
    struct node * head, *p;
    之后,申请内存,连接
    p=( struct node * ) malloc( sizeof( struct node ) );
    p->next = NULL;
    赋表头:
    head=p;
    循环:
    while(1) {
      if(结束条件)
        break;
      (取得屏幕点坐标)
      p->x = x坐标;
      p->y = y坐标;
      p->next = ( struct node * )malloc( szieof( struct node ) );
      p = p->next;
      p->next = NULL;
    }接着就是输出:
    p=head;
    while( p != NULL ) {
      printf( "%d,%d\n",p->x,p->y );
      p = p->next;
    }就这么多!
      

  2.   

    typedef struct ptr
    {
    int  buf;
    struct ptr* next;
    struct ptr* pre;
    }ptr;void CTestDlg::OnButton10() 
    {
    ptr* p;
    p=new ptr;
    p->buf=0;
    ptr* p1=p; for(int i=1;i<5;i++)
    {
    p->next=new ptr;
    ptr* p0=p;
    p->buf=i;   
    p=p->next; 
    p->pre=p0;
    } p->next=p1;
    p1->pre=p;

    }
      

  3.   

    struct point
    {
       int x;
       int y;
    };vector <point> vectorPoint;