单链表-数据结构

1 using System;
2 using System.Collections.Generic;
3 using System.Text;
4
5 namespace SSS
6 {
7 public class Node
8 {
9 public object element;
10 public Node link;
11
12 public Node()
13 {
14 element = null;
15 link = null;
16
17 }
18
19 public Node(object item)
20 {
21 element = item;
22 this.link = null;
23 }
24
25 }
26
27 public class LinkList
28 {
29 public Node head;
30 public LinkList Next;
31
32 public LinkList()
33 {
34 head = new Node("header");
35 }
36
37 public Node findNode(object item)
38 {
39 Node current = new Node();
40 current=head;
41 while (current.element != item)
42 {
43 current = current.link;
44 }
45 return current;
46
47 }
48
49 public void insertNode(object item,object after)
50 {
51 Node current = new Node();
52 Node newNode=new Node(item);
53 current = findNode(after);
54 if (current != null)
55 {
56 newNode.link = current.link;
57 current.link = newNode;
58 }
59 }
60
61 public void Del(object item)
62 {
63 Node current = new Node();
64 current = findPre(item);
65 Node pre = new Node();
66 if (current != null)
67 current.link = current.link.link;
68 }
69
70 public Node findPre(object item)
71 {
72 Node current = head;
73 while (!(current.link.element != item) && (current.link != null))
74 {
75 current = current.link;
76 }
77 return current;
78 }
79
80 public void PrintList()
81 {
82 Node current = new Node();
83 current = this.head;
84 while (current != null)
85 {
86 Console.WriteLine(current.element);
87 current = current.link;
88 }
89 }
90 }
91
92 class RRR
93 {
94 static void Main(string[] args)
95 {
96 Node firstNode = new Node("firstNode");
97 Node secNode = new Node("secNode");
98 Node thiNode = new Node("11");
99 firstNode.link = secNode;
100 secNode.link = thiNode;
101 thiNode.link = null;
102 LinkList myList = new LinkList();
103 myList.head.link = firstNode;
104 myList.PrintList();
105 myList.insertNode("hanwujibaby","firstNode");
106 myList.PrintList();
107 myList.Del("hanwujibaby");
108 myList.PrintList();
109 System.Threading.Thread.Sleep(8000);
110 }
111 }

 

转载于:https://www.cnblogs.com/jRoger/articles/1798872.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值