user-0 提问: 链表问题

回复:
user: user-1
content: #include<stdio.h> #include<stdlib.h>  struct shoplist {     char Name[20];     int num;     float price;     float distance;     struct shoplist* pNext; };  int iCount;  struct shoplist* Create() {     struct shoplist* pHead = NULL;     struct shoplist* pEnd,*pNew;      iCount = 0;     pEnd = pNew =(struct shoplist*)malloc(sizeof(struct shoplist));     printf("Please enter the name:\n");     //scanf("%s",&pNew->Name);     scanf("%s", pNew->Name);     printf("Please enter the amount:\n");     scanf("%d", &pNew->num);     printf("Please enter the price:\n");     //scanf("%.2f", &pNew->price);     scanf("%f", &pNew->price);     printf("Please enter the distance/(km):\n");     //scanf("%.2f",&pNew->distance);     scanf("%f", &pNew->distance);     while(pNew->num != 0)     {         iCount ++;         if(iCount == 1)         {             pNew->pNext = pHead;             pEnd = pNew;             pHead = pNew;         }         else         {             pNew->pNext = NULL;             pEnd->pNext = pNew;             pEnd = pNew;         }         pNew = (struct shoplist*)malloc(sizeof(struct shoplist));         printf("Please enter the name:\n");         //scanf("%s",&pNew->Name);         scanf("%s", pNew->Name);         printf("Please enter the amount:\n");         scanf("%d", &pNew->num);         printf("Please enter the price:\n");         //scanf("%.2f",&pNew->price);         scanf("%f", &pNew->price);         printf("Please enter the distance/(km):\n");         //scanf("%.2f",&pNew->distance);         scanf("%f", &pNew->distance);     }      free(pNew);      return pHead;  }  void Print(struct shoplist* pHead) {     struct shoplist *pTemp;     int iIndex = 1;      printf("-----the list has %d classes:-----\n",iCount);     printf("\n");     pTemp = pHead;      while(pTemp != NULL)     {         printf("the NO%d class is:\n",iIndex);         printf("the name is:%s\n",pTemp->Name);         printf("the amount is:%d\n",pTemp->num);         printf("the price is:%.2f\n",pTemp->price);         printf("the distance is:%.2f\n",pTemp->distance);         printf("\n");         pTemp = pTemp->pNext;         iIndex ++;     } }  struct shoplist* Insert(struct shoplist* pHead) {     struct shoplist* pNew;     printf("---Insert new member at first---\n");     pNew = (struct shoplist*)malloc(sizeof(struct shoplist));      //scanf("%s",&pNew->Name);     scanf("%s", pNew->Name);     scanf("%d",&pNew->num);     //scanf("%.2f",&pNew->price);     scanf("%f",&pNew->price);     //scanf("%.2f",&pNew->distance);     scanf("%f", &pNew->distance);      pNew->pNext = pHead;     pHead = pNew;     iCount++;      return pHead; }  //void Delete(struct shoplist* pHead,int iIndex) struct shoplist *Delete(struct shoplist* pHead,int iIndex) {     int i;     struct shoplist* pTemp;     struct shoplist* pPre;     pTemp = pHead;     pPre = pTemp;      printf("---delete NO%d member---\n",iIndex);     if (iIndex == 1) {         pTemp = pHead;         pHead = pHead->pNext;         free(pTemp);         iCount--;         return pHead;     }     //for( i=1 ; i<iIndex ; i++ )     for( i = 1 ; i<iIndex ; i++ )     {          pPre = pTemp;         pTemp = pTemp->pNext;      }     pPre->pNext = pTemp->pNext;     free(pTemp);     iCount--;      return pHead; }  int main() {     struct shoplist* pHead;      pHead = Create();     Print(pHead);     pHead = Insert(pHead);     Print(pHead);     pHead = Delete(pHead,2);     Print(pHead);      return 0; } 供参考～  建议对比一下，找出自己的问题～

user: user-2
content: 数据结构对单链表进行数据排序 http://bbs.csdn.net/topics/392201633