Created
November 23, 2011 03:39
-
-
Save zaman/1387825 to your computer and use it in GitHub Desktop.
oncelikli kuyruk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
#-*-coding:utf-8-*- | |
class oncelikli_kuyruk: | |
def __init__(self): | |
self.items = [] | |
def peek(self): | |
return self.items[0] | |
def enq(self, item, priority): | |
if self.isEmpty(): | |
return self.items.insert(0, (item, priority)) | |
else: | |
peek = self.peek() | |
if priority < peek[1]: | |
return self.items.insert(0, (item, priority)) | |
else: | |
for ind, i in enumerate(self.items[::-1]): | |
if priority == i[1]: | |
return self.items.insert(self.size() - ind, (item, priority)) | |
elif priority > i[1]: | |
return self.items.append((item, priority)) | |
def deq(self): | |
if self.isEmpty(): | |
return "the enqueue is empty" | |
else: | |
return self.items.pop(0) | |
def size(self): | |
return len(self.items) | |
def isEmpty(self): | |
return self.items == [] | |
#foo=oncelikli_kuyruk() | |
#foo.enq(2,3) | |
#foo.enq(4,5) | |
#foo.peek() | |
#foo.deq() | |
#foo.size() | |
#foo.deq() | |
#foo.deq() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment