| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 431 人关注过本帖
标题:请大虾们帮帮忙 谢谢
只看楼主 加入收藏
cjl730
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2008-10-28
收藏
 问题点数:0 回复次数:0 
请大虾们帮帮忙 谢谢
#include <stdio.h>
#include <stdlib.h>
#define MAX 10
struct List
{
   int Number;
   int Total;
   struct List *Next;
};
typedef struct List Node;
typedef Node *Link;

int Data[2][MAX] = { 1, 3, 5, 7, 2, 6, 8, 9, 0, 4,
                    15,35,10,67,25,65,38,70,30,20};
/* Create List */

Link Create_List( Link Head )
{
   Link Pointer;
   Link New;
   int i;
   Head = ( Link ) malloc( sizeof( Node ) );
   if( Head == NULL )
   {
      printf("Memory allocate fainure!!\n");
   }
   else
   {
      Head->Number = Data[0][0];
      Head->Total = Data[1][0];
      Head->Next = NULL;

      Pointer = Head;

      for( i =1; i < MAX; i ++)
      {
         New = ( Link ) malloc( sizeof( Node ) );
         New->Number = Data[0][i];
         New->Total = Data[1][i];
         New->Next = NULL;
         Pointer->Next = New;
         Pointer = New;
      }
   }
   return Head;
}

/* Insert List */

Link Insert_List( Link Head, Link New, int Key )
{
   Link Pointer;
   Pointer = Head;
   while( 1 )
   {
      if( Pointer == NULL )
      {
         New->Next = Head;
         Head = New;
         break;
      }
      if( Pointer->Next == Key )
      {
         New->Next = Pointer->Next;
         Pointer->Next = New;
         break;
      }

      Pointer = Pointer->Next;


   }
   return Head;
}

/* Print List */

void Print_List( Link Head )
{
   Link Pointer;
   Pointer = Head;
   while( Pointer != NULL )
   {
      printf("[%d,%d]" , Pointer->Number, Pointer->Total);
      Pointer = Pointer->Next;
   }
   printf("\n");
}

/* Free List */

void Free_List( Link Head )
{

   Link Pointer;
   while( Head != NULL )
   {
      Pointer = Head;
      Head = Head->Next;
      free( Pointer );
   }
}

int main()
{
   Link Head;
   Link New;
   int Key;
   Head = Create_List( Head );
   if( Head != NULL )
   {
      Print_List( Head );
      while( 1 )
      {
         printf("Input 0 to Exit\n");
         New = ( Link ) malloc( sizeof( Node ) );
         printf("please input the data number : ");
         scanf("%d",&New->Number);
         if( New->Number == 0 )
           break;
         printf("Please input the data total : ");
         scanf("%d" , &New->Total) ;
         printf("please input the data number for insert");
         scanf("%d" , &Key);
         Head = Insert_List( Head, New, Key );
         Print_List( Head );
      }
      Free_List( Head );
   }
   getch();
}
搜索更多相关主题的帖子: include Memory Create 
2008-12-13 11:25
快速回复:请大虾们帮帮忙 谢谢
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015759 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved