Skip to content

Commit e42c321

Browse files
build list
1 parent 74ffd86 commit e42c321

3 files changed

Lines changed: 175 additions & 40 deletions

File tree

.idea/workspace.xml

Lines changed: 95 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lists.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
class Node:
2+
def __init__(self, initdata):
3+
self.data = initdata
4+
self.next = None
5+
6+
def getData(self):
7+
return self.data
8+
9+
def getNext(self):
10+
return self.next
11+
12+
def setData(self, newdata):
13+
self.next = newdata
14+
15+
def setNext(self, nextNode):
16+
self.next = nextNode
17+
18+
19+
temp = Node(93)
20+
temp.setData(10)
21+
print(temp.getNext())
22+
23+
# 定义一个无序链表
24+
class UnorderedList:
25+
def __init__(self):
26+
self.head = None
27+
28+
def isEmpty(self):
29+
return self.head == None
30+
31+
def add(self, item):
32+
temp = Node(item)
33+
temp.setNext(self.head)
34+
self.head = temp
35+
36+
def size(self):
37+
current = self.head
38+
count = 0
39+
while current != None:
40+
count += 1
41+
current = current.getNext()
42+
return count
43+
44+
def search(self, item):
45+
current = self.head
46+
found = False
47+
while current != None and not found:
48+
if current.getData() == item:
49+
found = True
50+
else:
51+
current = current.getNext()
52+
return found
53+
54+
def remove(self, item):
55+
current = self.head
56+
previous = None
57+
found = False
58+
while not found:
59+
if current.getData() == item:
60+
found = True
61+
else:
62+
previous = current
63+
current = current.getNext()
64+
65+
if previous == None:
66+
self.head = current.getNext()
67+
else:
68+
previous.setNext(current.getNext())
69+
70+
myList = UnorderedList()
71+
myList.add(31)
72+
myList.add(77)
73+
myList.add(17)
74+
myList.add(93)
75+
myList.add(26)
76+
myList.add(54)
77+
print(myList.search(17))
78+
myList.remove(54)
79+
print(myList.search(54))

SVM/SVM.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from numpy import *
2-
2+
# 代码来自机器实战
33
def loadDataSet(fileName):
44
dataMat = []; labelMat = []
55
fr = open(fileName)

0 commit comments

Comments
 (0)