
import ctypes
class DequeArray:
def __init__(self):
self.capacity = 5
capacity = self.capacity
self._data = self._make_array(self.capacity)
self._size = 0
self._front = 0
def _make_array(self, c):
capacity = self.capacity
return(capacity*ctypes.py_object)()
def isEmpty(self) :
if self._data == 00:
return False
else:
return True
def __len__(self):
return self._size
def __getitem__(self, index): #return element at index k
if not 0 <= index <self._size:
raise IndexError('invalid index')
return self._data[index]
def __setitem__(self, index, value):
if not 0 <= index <self._size:
raise IndexError('invalid index')
self._data[index] = value
def append(self, item):
if self._size == self.capacity:
self._data.pop(0)
else:
avail = (self._front + self._size)% len(self._data)
self._data[avail] = item
self._size += 1
def preappend(self, item): # update front index after preappend
for index in range(self._size()):
index+=1
self._front = 0
self._size = index
self.insert(self._front,value)
def removeFirst(self): #update index after removal
if self._size == self.capacity:
self._data.pop(0)
else:
answer = self._data[self._front]
self._data[self._front] = None
self._front = (self._front + 1)%len(self._data)
self._size -= 1
return answer
def removeLast(self):
if self._size == self.capacity:
self._data.pop(0)
else:
value = self._data[self._size]
self._data[self._size] = None
self._size -= 1
return value
def insert(self, index, item):
if self._size == self.capacity:
self._data.pop(self._data[self._size])
temp = index
for index in (index, self._size()):
index+=1
self.__setitem__(temp, item)
# def remove(self, index, item):
# def print(self):
d = DequeArray()
print(d.isEmpty())
d.insert(1,10)
d.append(2)
d.preappend(3)
print(d.__len__())
print(d.__getitem__(1)) # return element at index k
d.__setitem__(2,5) # set value 5 at index 2
print(d.removeFirst())
print(d.removeLast())
print(d.remove(0)) #Remove and return the item at the index, and shift the subsequent items
print(d.print())
Need help the first picture is the code I have so far the second are the...
PYTHON. Continues off another code. I don't understand this. Someone please help! Comment the lines please so I can understand LinkedList ADT: class myLinkedList: def __init__(self): self.__head = None self.__tail = None self.__size = 0 def insert(self, i, data): if self.isEmpty(): self.__head = listNode(data) self.__tail = self.__head elif i <= 0: self.__head = listNode(data, self.__head) elif i >= self.__size: self.__tail.setNext(listNode(data)) self.__tail = self.__tail.getNext() else: current = self.__getIthNode(i - 1) current.setNext(listNode(data,...
PYTHON. Continues off another code(other code is below). I don't understand this. Someone please help! Comment the lines please so I can understand. There are short and med files lengths for each the list of names/ids and then search id file. These are the input files: https://codeshare.io/aVQd46 https://codeshare.io/5M3XnR https://codeshare.io/2W684E https://codeshare.io/5RJwZ4 LinkedList ADT to store student records(code is below). Using LinkedList ADT instead of the Python List. You will need to use the Student ADT(code is below) Imports the Student class...
attention!!!!!!! I need python method!!!!!!!!!
the part which need to edit is below: i need python
one!!!!!!!!!
the part below is interface for the range search tree which
don’t need to modify it.
Week 3: Working with a BST TODO: Implement a Binary Search Tree (Class Name: RangesizeTree) Choose one language fromJava or Python. Iin both languages,there is an empty main function in the Range Size Tree file. The main function is not tested, however, it is provided for you...
help finish Queue, don't think
I have the right thing.
# 1. After studying the Stack class and testStack() functions in stack.py # complete the Queue class below (and test it with the testQueue function) # # 2. Afer studying and testing the Circle class in circle.py, # complete the Rectangle class below (and test it with the testRectangle function) # # # 3. SUBMIT THIS ONE FILE, with your updates, TO ICON. # # # NOTE: you may certainly...
Help me solve this in C++ Rewrite the code to use array instead of linked lists. Please do not change anything besides the data structure. Instead of linked list use an array. The functionality should remain exactly the same. You can prepare a class if you wish but it is not required. /** * Queue implementation using linked list C style implementation ( no OOP). */ #include <cstdio> #include <cstdlib> #include <climits> #include <iostream> #define CAPACITY 100 // Queue max...
- Complete the code to solve a maze- Discuss related data structures topicsProgramming-----------In this part, you will complete the code to solve a maze.Begin with the "solveMaze.py" starter file.This file contains comment instructions that tell you where to add your code.Each maze resides in a text file (with a .txt extension).The following symbols are used in the mazes:BARRIER = '-' # barrierFINISH = 'F' # finish (goal)OPEN = 'O' # open stepSTART = 'S' # start stepVISITED = '#' #...
My Question is: I have to modify this program, even a small modification is fine. Can anyone give any suggestion and solution? Thanks in Advanced. import java.util.*; class arrayQueue { protected int Queue[]; protected int front, rear, size, len; public arrayQueue(int n) { size = n; len = 0; Queue = new int[size]; front = -1; rear = -1; } public boolean isEmpty() { return front == -1; } public boolean isFull() { return front == 0 && rear ==size...
PART A - STACKS To complete this assignment: Please study the code posted below. Please rewrite the code implementing a template class using a linked list instead of an array. Note: The functionality should remain the same *************************************************************************************************************** /** * Stack implementation using array in C/procedural language. */ #include <iostream> #include <cstdio> #include <cstdlib> //#include <climits> // For INT_MIN #define SIZE 100 using namespace std; /// Create a stack with capacity of 100 elements int stack[SIZE]; /// Initially stack is...
Doubly Linked List Java Help Details: First, read the DoublyLinkedList.java code and try to understand what each field stores and what each method is doing. Modify and complete the class as described below •The field size was defined in the class but was never maintained. Set the current default value and modify it whenever it is needed in the existing methods and other methods you implement as it is needed. It should always include the number of Nodes inside the...
Hey I have a task which consists of two part. Part A asks for
writing a program of WORD & LINE CONCORDANCE
APPLICATION in python which I have completed it.
Now the second part has given 5 dictionary implementation codes
namely as: (ChainingDict, OpenAddrHashDict with linear probing,
OpenAddrHashDict with quadratic probing, and 2 tree-based
dictionaries from lab 12 (BST-based dictionary implementation) and
asks for my above program WORD & LINE CONCORDANCE
APPLICATION to use these implemented code and
show the time...