code problem

This is a discussion on code problem within the C Programming forums, part of the General Programming Boards category; I am trying to do insertion sort with list (ADT), I wrote the function InsertionSortList in the sort.c file: Code: ...

  1. #1
    Compiling
    Join Date
    Jun 2003
    Posts
    69

    code problem

    I am trying to do insertion sort with list (ADT), I wrote the function InsertionSortList in the sort.c file:
    Code:
    void
    InsertionSortList(List L)
    {
      Position P1, P2;
      ElementType temp;
      for(P1 = L; P1->Next != NULL; P1 = P1->Next)  //problem
        {
          temp = P1->Element; //problem
          for(P2 = P1; (P2->Last != NULL) && (P2->Last->Element < P2->Element); P2 = P2->Last) //problem
    	P2->Element = P2->Last->Element; //problem
        }
    }
    while i am compling my programme, the gcc complier said:
    dereferencing pointer to incomplete type
    these problems happend at the lines which I indicate in the function

    How can I deal with it? Thx a lot!

  2. #2
    Compiling
    Join Date
    Jun 2003
    Posts
    69
    The sort.c file, may be useful.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    51
    can you post the headers "fatal.h" and "list.h". I have a feeling that you have just declared the structures but haven't actually defined them.

    ie. You told the compiler a structure name but haven't given any body to that name.

  4. #4
    Compiling
    Join Date
    Jun 2003
    Posts
    69
    list.c
    Attached Files Attached Files

  5. #5
    Compiling
    Join Date
    Jun 2003
    Posts
    69
    list.h
    Attached Files Attached Files
    • File Type: h list.h (783 Bytes, 64 views)

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    51
    yup, this code

    Code:
     /* Place in the interface file */
            struct Node
            {
                ElementType Element;
                Position    Next;
    	    Position    Last;
            };
    is in list.c

    put it into list.h

  7. #7
    Compiling
    Join Date
    Jun 2003
    Posts
    69
    could you tell me where shold I put it in list.h?
    thx

  8. #8
    Registered User
    Join Date
    Aug 2003
    Posts
    51
    in list.h

    the line
    Code:
    struct Node;
    replace it with the structure body.

  9. #9
    Compiling
    Join Date
    Jun 2003
    Posts
    69
    thank you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code problem
    By sybariticak47 in forum C++ Programming
    Replies: 9
    Last Post: 02-28-2006, 10:50 AM
  2. Problem with game code.
    By ajdspud in forum C++ Programming
    Replies: 5
    Last Post: 02-14-2006, 05:39 PM
  3. problem with selection code
    By DavidP in forum Game Programming
    Replies: 1
    Last Post: 06-14-2004, 01:05 PM
  4. Replies: 5
    Last Post: 12-03-2003, 04:47 PM
  5. Help with code for simple Y2K problem
    By Mule in forum C++ Programming
    Replies: 3
    Last Post: 03-05-2003, 11:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21