设为首页 加入收藏

TOP

链表的头文件及简单的应用(三)
2013-10-17 09:08:05 来源: 作者: 【 】 浏览:490
Tags:文件 简单 应用

 

  else

  {

  pre = list->head;

  while(pre->next != node)

  pre = pre->next;

  node_delete(node, pre);

  }

  return list;

  }

  nodetype * list_add(listtype *list, int data)

  {

  nodetype *cur, *temp;

  for (cur = list->head;

  cur != NULL && cur->next != NULL;

  cur = cur->next)

  ;

  temp = (nodetype *)malloc(sizeof(nodetype));

  temp->data = data;

  temp->next = NULL;

  if (list->length == 0)

  list->head = temp;

  else

  cur->next = temp;

  list->length++;

  return temp;

  }

  void error(int err)

  {

  switch(err)

  {

  case 1:

  printf("RAM error!\n");

  break;

  case 2:

  printf("Length error!\n");

  break;

  case 3:

  printf("Location error!\n");

  break;

  default:

  printf("Unknown error!\n");

  }

  exit(EXIT_FAILURE);

  }

  以下是一些功能的测试

  test.c:

  [cpp]

  #include <stdio.h>

  #include "list.h"

  int main(void)

  {

  listtype *list;

  int length, location, data;

  list = list_create();

  for (;;)

  {

  printf("Please input the length of the list:");

  scanf("%d", &length);

  if (length <= 0)

  break;

  list_input(list, length);

  list_print(list);

  }

  for (;;)

  {

  printf("Please input the data you want to insert:");

  scanf("%d", &data);

  printf("The location:");

  scanf("%d", &location);

  if (location < 0)

  break;

  list_insert(list, location, data);

  list_print(list);

  }

  for(;;)

  {

  printf("Please input the data you want to delete:");

  scanf("%d", &data);

  if(data == 0)

  break;

  list_delete(list, data);

  list_print(list);

  }

  return 0;

  }

        

首页 上一页 1 2 3 下一页 尾页 3/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++小知识之如何看工程类型 下一篇C++小知识之wsprintf使用

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: