| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 462 人关注过本帖
标题:求助:两个单向链表的删除
只看楼主 加入收藏
alln
Rank: 2
等 级:论坛游民
帖 子:3
专家分:10
注 册:2010-6-2
结帖率:0
收藏
已结贴  问题点数:20 回复次数:4 
求助:两个单向链表的删除
struct node
{
    int num;
    struct *next;
}
struct node *head1,*head2;
请问如何删除head1和head2中num相同的节点
head1中所有节点的num值都不同
head2中所有节点的num值也不同
搜索更多相关主题的帖子: 链表 删除 
2010-07-27 12:43
sunyh1999
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:14
帖 子:1178
专家分:3032
注 册:2009-5-17
收藏
得分:5 
这个网址你看看吧,会对你有帮助的: http://

欢迎来到我的博客:http://blog..cn/noisunyuhong
2010-07-27 14:18
encounter
Rank: 5Rank: 5
来 自:扬州
等 级:职业侠客
威 望:2
帖 子:150
专家分:359
注 册:2010-7-24
收藏
得分:5 
回复 2楼 sunyh1999
学习中
不错

ping   nbtstat   netstat   tracert    nat   at    ftp   telnet..................
2010-07-27 15:29
pingf
Rank: 2
等 级:论坛游民
帖 子:33
专家分:66
注 册:2010-7-25
收藏
得分:5 
回复 楼主 alln
贴个经典的双链表
#ifndef _LIST_H
#define _LIST_H 1

/* The definitions of this file are adopted from those which can be
   found in the Linux kernel headers to enable people familiar with
   the latter find their way in these sources as well.  */


/* Basic type for the double-link list.  */
typedef struct list_head
{
  struct list_head *next;
  struct list_head *prev;
} list_t;


/* Define a variable with the head and tail of the list.  */
#define LIST_HEAD(name) \
  list_t name = { &(name), &(name) }

/* Initialize a new list head.  */
#define INIT_LIST_HEAD(ptr) \
  (ptr)->next = (ptr)->prev = (ptr)


/* Add new element at the head of the list.  */
static inline void
list_add (list_t *newp, list_t *head)
{
  head->next->prev = newp;
  newp->next = head->next;
  newp->prev = head;
  head->next = newp;
}


/* Add new element at the tail of the list.  */
static inline void
list_add_tail (list_t *newp, list_t *head)
{
  head->prev->next = newp;
  newp->next = head;
  newp->prev = head->prev;
  head->prev = newp;
}


/* Remove element from list.  */
static inline void
list_del (list_t *elem)
{
  elem->next->prev = elem->prev;
  elem->prev->next = elem->next;
}


/* Join two lists.  */
static inline void
list_splice (list_t *add, list_t *head)
{
  /* Do nothing if the list which gets added is empty.  */
  if (add != add->next)
    {
      add->next->prev = head;
      add->prev->next = head->next;
      head->next->prev = add->prev;
      head->next = add->next;
    }
}


/* Get typed element from list at a given position.  */
#define list_entry(ptr, type, member) \
  ((type *) ((char *) (ptr) - (unsigned long) (&((type *) 0)->member)))



/* Iterate forward over the elements of the list.  */
#define list_for_each(pos, head) \
  for (pos = (head)->next; pos != (head); pos = pos->next)


/* Iterate forward over the elements of the list.  */
#define list_for_each_prev(pos, head) \
  for (pos = (head)->prev; pos != (head); pos = pos->prev)


/* Iterate backwards over the elements list.  The list elements can be
   removed from the list while doing this.  */
#define list_for_each_prev_safe(pos, p, head) \
  for (pos = (head)->prev, p = pos->prev; \
       pos != (head); \
       pos = p, p = pos->prev)

#endif  /* list.h */

2010-07-27 18:27
BJ_BOY
Rank: 4
等 级:业余侠客
威 望:1
帖 子:77
专家分:225
注 册:2010-2-4
收藏
得分:5 
楼主是想要带头结点的单链表,还是无头结点(仅有头指针)的单链表。这两种类型的代码是不一样的!
2010-07-28 15:15
快速回复:求助:两个单向链表的删除
数据加载中...
 
   



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

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