Skip to main content

Simple Queue Implementation using Python

Stacks and Queues are not data structures, they are basically abstract data types. The simple data structure can be an array or a linked list.

Queues are FIFO.. First In and First Out.

Queues do have real world operations like:-
1.    Token System
2.    Organising data to archive based on age.
3.    Scheduling
4.    Any task which involves first come first serve basis.

Below is a simple implementation of Queue using Python.

 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
class Queue:

    def __init__(self):
        self.queue = []

    def isEmpty(self):
        return self.queue == []

    def enqueue(self, data):
        self.queue.append(data)

    def dequeue(self):
        data = self.queue[0]
        del self.queue[0]
        return data

    def peek(self):
        return self.queue[0]

    def sizeQueue(self):
        return len(self.queue)

    def dispQueue(self):
        for l in range(0,len(self.queue)):
            print ("Position {0} Element is {1}".format(l,self.queue[l]))

'''-------------------------- Main Code ------------------------------------'''
i = 0
numberOfElements =int(input("Enter number of Elements to enqueue to queue:        "))
userqueue = Queue()

for i in range(0, numberOfElements):
    number =int(input("Enter the {0} item number to enqueue to queue at first:        ".format(i)))
    userqueue.enqueue(number)

print("Size of queue is : {0} ".format(userqueue.sizeQueue()))
print("dequeue: ",userqueue.dequeue())

userqueue.dispQueue()




Comments

Popular posts from this blog

Appian UUID vs ID

IDs in Appian:- There are 2 kinds of IDs which are observed in Appian namely UUIDs and IDs. Let’s go through them briefly.  Many of the functionalities are covered by Smart Services hence the explicit use of Ids are reduced or those can be done by relational database entries in some special cases. Sources: Appian Documentation Appian Community

Creating first Application in Appian BPM

Appian is well-equipped with Business Process Management (BPM) and Case Management capabilities. From a viewpoint it’s also pretty efficient like its counter parts such as  Pegasystems, TIBCO, INFOR etc. We will be going through a series of features, tips and the practices which may be helpful in giving a better insight. To Kick off, let’s have a look on how to kick off an application in Appian within seconds. Now In Appian there are 3 ways you can create an application. 1. From Scratch 2. Using Application Builder (Basic) 3. Using Application Builder (Full) When we create from Scratch then we need to give “Name” and “Description”. It’s like Appian will just create a placeholder to create and build related objects. When using builder we need to give “Data Source” beforehand.   In addition to process model and interfaces, this full application option will also create objects related to reporting documentation and task etc. It has created around ...