-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdoublyLinkedList.py
More file actions
68 lines (51 loc) · 1.46 KB
/
doublyLinkedList.py
File metadata and controls
68 lines (51 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from os import listdir
from os.path import isfile,join
class Node:
def __init__(self,data):
self.data = data
self.next = None
self.prev = None
class Doublylinkedlist:
def __init__(self):
self.head = None
def insert(self,newData):
newNode = Node(newData)
if self.head is None:
self.head = newNode
newNode.next = self.head
newNode.prev = self.head
return
temp = self.head
while(temp.next is not self.head):
temp = temp.next
newNode.prev = temp
temp.next = newNode
self.head.prev = newNode
newNode.next = self.head
def display(self):
temp = self.head
while(temp is not self.head.prev):
print(temp.data," ")
temp = temp.next
print(self.head.prev.data)
def getNext(self):
return self.head.next.data
def getPrev(self):
return self.head.prev.data
def getFileName(self,path):
files = [f for f in listdir(path) if isfile(join(path,f))]
mp3Files = []
for i in files:
if '.mp3' in i:
mp3Files.append(i)
return mp3Files
dlist = Doublylinkedlist()
listFiles = dlist.getFileName("C:\\Users\\vkjof\Desktop\\Networks Final")
for i in listFiles:
dlist.insert(i)
dlist.display()
d1 = dlist.getNext()
d2= dlist.getPrev()
print("present",dlist.head.data)
print("next",d1)
print("prev",d2)