473,407 Members | 2,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

sorting link list

36
what`s the warning message bout ?

line 47: error C2037: left of 'value' specifies undefined struct/union 'Node'

TNX ......

the code:
Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct
  5. {
  6.     int value;
  7.     struct Node* next;
  8. }Node;
  9.  
  10.  
  11. Node* newList(Node *head)
  12. {
  13.     Node *temp;
  14.     int size,i;
  15.     printf("size?");
  16.     scanf("%d",&size);  
  17.     for(i=0; i<size; i++)
  18.     {
  19.         temp=(Node*)malloc(sizeof(Node));
  20.         temp->next=head;
  21.         head=temp;
  22.         printf("value(%d)=?",i+1);
  23.             scanf("%d",&(head->value));
  24.     }
  25.     return(head);
  26. }
  27.  
  28. void printList(Node*head)
  29. {
  30.     Node* current=head;
  31.     while(current!=0)
  32.     {
  33.         printf("%d\n",current->value);
  34.         current=current->next;
  35.     }
  36. }
  37.  
  38.  
  39. sort_list(Node*list)
  40. {
  41.     Node* current=list;
  42.     while(current!=NULL)
  43.     {
  44.         current=list;
  45.         while(current!=NULL)
  46.         {
  47.             if((current->next)->value < current->value)
  48.             {
  49.                 //swap
  50.             }
  51.             current=current->next;
  52.         }
  53.         list=list->next;
  54.     }
  55.  
  56. }
  57.  
  58.  
  59.  
  60. int main(void)
  61. {
  62.     Node *head=NULL;
  63.     int sel=-1;
  64.     while(sel!=0)
  65.     {
  66.            printf("1. enter new list\n"
  67.                   "2. print list\n"
  68.                   "3. sort list by value\n"
  69.                   "4. enter node by value\n"
  70.                   "5. reverse list\n"
  71.                   "6. delete node\n"
  72.                   "7. free list\n"
  73.                   "0. quit\n"
  74.                   "==>");
  75.            scanf("%d",&sel);
  76.            switch(sel)
  77.            {
  78.                case 1:
  79.                    head=newList(head);
  80.                    break;
  81.  
  82.                case 2:
  83.                    printList(head);
  84.                    break;
  85.                //case 3:
  86.  
  87.            }
  88.     }
  89. }
  90.  
Sep 13 '09 #1
4 3487
weaknessforcats
9,208 Expert Mod 8TB
Your problem is here:

Expand|Select|Wrap|Line Numbers
  1. typedef struct 
  2.     int value; 
  3.     struct Node* next; 
  4. }Node; 
This says that struct Node is now Node. BUT the typedef is after the compiler has seen the member struct Node* next. Therefore, while the struct is now Node, the member is still struct Node*.

Do this:

Expand|Select|Wrap|Line Numbers
  1. struct Node
  2.     int value; 
  3.     struct Node* next; 
  4. }; 
  5. typedef struct Node Node;
Now struct Node is now Node. So when the compiler sees the struct Node* member it will accept Node* since it knows that struct Node and Node are the same type.
Sep 13 '09 #2
JosAH
11,448 Expert 8TB
There is no "struct Node" defined, only an alias for that (unnamed) struct is defined by that typedef; make it:

Expand|Select|Wrap|Line Numbers
  1. typedef struct _Node
  2.     int value; 
  3.     struct _Node* next; 
  4. }Node; 
  5.  
kind regards,

Jos

edit: too late ;-)
Sep 13 '09 #3
weaknessforcats
9,208 Expert Mod 8TB
JosAH solution combines my solution of two statements into one statement. The effect is the same. The JosAH solution is the one I usually see in production code.
Sep 13 '09 #4
sedaw
36
ok...., thank you very much !
Sep 13 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: p0wer | last post by:
Let's suppose I have this sample document: <root> <entry id="1" <date>2003-08-03</date> <param_1>5</param_1> <param_2>10</param_2> </entry> <entry id="2"> ...
19
by: Owen T. Soroke | last post by:
Using VB.NET I have a ListView with several columns. Two columns contain integer values, while the remaining contain string values. I am confused as to how I would provide functionality to...
0
by: Brian Henry | last post by:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another...
4
by: FBM | last post by:
Hi, I am working on a program that simulates one of the elements of ATM. The simulation stores events which occurs every some milliseconds for a certain amount of time. Every time that an event...
20
by: martin-g | last post by:
Hi. Mostly I program in C++, and I'm not fluent in C# and .NET. In my last project I began to use LinkedList<and suddenly noticed that can't find a way to sort it. Does it mean I must implement...
9
by: robin9876 | last post by:
I have a list of integers (example sub set of data below), what is the best method of sorting these in code? 1, 872 5, 1283 8, 343 9, 123
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
1
KevinADC
by: KevinADC | last post by:
Introduction In part one we discussed the default sort function. In part two we will discuss more advanced techniques you can use to sort data. Some of the techniques might introduce unfamiliar...
5
by: kylie991 | last post by:
I'm confused as to why this isnt working.. am i doing this right?? I have to create a function that does the following: - Insert a word to the linked list so that the list // ...
5
by: jrod11 | last post by:
hi, I found a jquery html table sorting code i have implemented. I am trying to figure out how to edit how many colums there are, but every time i remove code that I think controls how many colums...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.