Linked list implementation (previous code)

Source: Internet
Author: User

Correct example//////////////////////////////////////////////////# include<stdio.h>//Call memory allocation function #include<stdlib.h>typedef struct node{ int data;  struct node *next;} linknode, *linklist;//function declaration: Create a linked list void creat (linklist *head);//function declaration, Reverse list Void inverse (LinkList  head);//function declaration: Output list Void output (Linklist head); Void  creat (Linklist &head)//Build table { linklist p = null; linklist q = null; head= (LinkList) malloc ( sizeof (Linknode)); head->next = null; q=head; while  (1)  {  p  =  (linklist) malloc (sizeof (Linknode)); &NBSP;&NBSP;P-&GT;NEXT&NBSP;=&NBSP;NULL;&NBSP;&NBSP;SCANF ("%d" ,  &p->data);  if  (0 == p->data)//Input 0 = end Input   {    free (p);    break;  }  q->next = p;  q = p; }        linklist w = head-> next; while  (null != w)  {  printf ("%d ",  w->data);   w = w->next; } printf ("\ n");} Void inverse (Linklist head)//Reverse { linklist p = head->next; linklist  tmp = null; head->next = null;  while  (NULL != p)  {   tmp = p->next;  p->next = head->next;  head-> Next = p;  p = tmp; }}void output (linklist head)//Output {  linklist p = head->next; while  (null != p)  {  printf ("%d   ",  p->data);   p = p->next; } printf (" \ n ");} Int main () { linklist head = null;      &nbsP; creat (head);          output (head);         inverse (head);         output (head);  return 0;} You must use the C + + compiler to successfully compile your program. Using the GCC compiler, the error message is as follows:/TMP/CCNR7EV3.O: (. eh_frame+0x12): undefined reference to  ' __gxx_ Personality_v0 ' collect2: ld returned 1 exit status ///////////////////////////// The following procedure is not just a grammatical problem//////////////////////////////////////////////////////////////#include    <stdio.h> #include   <stdlib.h>typedef struct node{ int data;  struct node *next;} linknode, *linklist; Linklist creat (Linklist head); Void inverse (Linklist head); Void output (LinkList  Head); Linklist creat (Linklist head)//Build table { linklist p = null; linklist q  = null; head =  (Linklist)  malloc  (sizeof (Linknode)); head->next = null; q = head;  while  (1)  {  p =  (linklist)  malloc  (sizeof (Linknode));  &NBSP;P-&GT;NEXT&NBSP;=&NBSP;NULL;&NBSP;&NBSP;SCANF ("%d",  &p->data);  if  (0 ==  p->data)//input 0 means end input   {   free (p);   break;  }   q->next = p;  q = p; } return head;} Void inverse (Linklist head)//Reverse { linklist p = head->next; linklist  tmp = null; head->next = null;  while  (NULL != p)  {   tmp = p->next;  p->next = head->next;  head-> Next = p;  p = tmp; }}void output (linklist head)//Output {  Linklist p = head->next; while  (null != p)  {  printf ("%d ",  p->data);   p =  p->next; } printf ("\ n");} Int main () { linklist head = null; head = creat (head);  Output (head) );  inverse (head);  output (head);  return 0;}   Summary: The failure to really carefully study the array in the sophomore days has led to a re-examination today. Copy the code today, still can't find the key to compile error in a short time. The following is a list of compile error messages:--------------------configuration:  List Class  - Win32  Debug--------------------Compiling ... Linked list class. Cpplinking ... Linked List class .obj : error lnk2001: unresolved external symbol  "struct node  * __cdecl creat (struct node *) "  ([Email protected]@[email protected]@[email &NBSP;PROTECTED]@Z) debug/linked list class .exe : fatal error lnk1120: 1 unresolved  Externalserror executing link.exe. List class. Exe - 2 error (s),  0 warning (s) After a more than 10-minute check, a final discovery error occurred on the definition function creat (linklist head), an E (Create (linklist head);) Fatal error is obviously intolerable.  

Linked list implementation (previous code)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.