数据结构代写 | CS261 Data Structures Assignment 3

本次美国代写主要为数据结构的代码修改assignment

CS261 Data Structures

Assignment 3

Your Very Own Linked List and Binary Search Practice

Part 1 -- Summary and Specific Instructions

  1. Implement Deque and Bag ADT interfaces with a Singly Linked List data structure by

completing the skeleton code provided in the file sll.py. Once completed, your

implementation will include the following methods:

add_front(), add_back()

insert_at_index()

remove_front(), remove_back()

remove_at_index()

get_front(), get_back()

remove()

count()

slice()

  1. We will test your implementation with different types of objects, not just integers.

We guarantee that all such objects will have correct implementations of methods

eq, lt, gt, ge, le, and str.

  1. The number of objects stored in the list at any given time will be between 0 and 900

inclusive.

  1. Variables in the SLNode and LinkedList classes are not marked as private. For this

portion of the assignment, you are allowed to access and change their values

directly. You are not required to write getter or setter methods for them.

  1. RESTRICTIONS: You are not allowed to use ANY built-in Python data structures or

their methods. All implementations in this part of the assignment must be

done recursively. You are not allowed to use while- or for- loops in this part

of the assignment.

  1. This implementation must be done with the use of front and back sentinel nodes.

add_front(self, value: object) -> None:

This method adds a new node at the beginning of the list (right after the front sentinel).

Example #1:

lst = LinkedList()

print(lst)

lst.add_front('A')

lst.add_front('B')

lst.add_front('C')

print(lst)

Output:

SLL\[\]

SLLC -\> B -\> A

add_back(self, value: object) -> None:

This method adds a new node at the end of the list (right before the back sentinel).

Example #1:

lst = LinkedList()

print(lst)

lst.add_back('C')

lst.add_back('B')

lst.add_back('A')

print(lst)

Output:

SLL\[\]

SLLC -\> B -\> A

insert_at_index(self, index: int, value: object) -> None:

This method adds a new value at the specified index position in the linked list. Index 0

refers to the beginning of the list (right after the front sentinel).

If the provided index is invalid, the method raises a custom "SLLException". Code for the

exception is provided in the skeleton file. If the linked list contains N nodes (not including

sentinel nodes in this count), valid indices for this method are 0, N inclusive.

Example #1:

lst = LinkedList()

test_cases = (0, 'A'), (0, 'B'), (1, 'C'), (3, 'D'), (-1, 'E'), (5, 'F')

for index, value in test_cases:

print('Insert of', value, 'at', index, ': ', end=")

try:

lst.insert_at_index(index, value)

print(lst)

except Exception as e:

print(type(e))

Output:

Insert of A at 0 : SLL A

Insert of B at 0 : SLL B -\> A

Insert of C at 1 : SLL B -\> C -\> A

Insert of D at 3 : SLL B -\> C -\> A -\> D

Insert of E at -1 : <class 'main.SLLException'>

Insert of F at 5 : <class 'main.SLLException'>

相关推荐
鬼手点金8 小时前
带工具调用的多轮交互:Agent 的核心循环
服务器·人工智能·windows·深度学习·microsoft·机器学习·交互
jiangliushi68 小时前
GPT-6.1 Sol 免费用:Windows 装完 Codex 提示“不是内部或外部命令”?三步加好 PATH
windows·gpt
H.莓飛9 小时前
【数据结构】快速排序专题
linux·服务器·c语言·数据结构·visual studio
猪腰子正9 小时前
深度学习环境安装教程-适用Windows系统
人工智能·windows·深度学习
重生之小比特9 小时前
【算法拾光】二分查找|在排序数组中查找元素的第一个和最后一个位置 + 搜索旋转排序数组
数据结构·算法·排序算法
2501_915106329 小时前
Windows 用 KXBuild 开发 iOS 项目,CocoaPods、SPM 怎么处理?
windows·vscode·ios·个人开发·swift·敏捷流程·cocoapods
公子小六9 小时前
基于.NET的Windows窗体编程之WinForms自定义控件(3)
windows·c#·.net·音视频·winforms
YukiRinLL9 小时前
查找与排序算法:复杂度、稳定性
数据结构·算法·排序算法
careathers20 小时前
【数据结构】从堆到 PriorityQueue:手写一个优先级队列
数据结构
y1su21 小时前
Leetcode 字符串模板
java·数据结构·算法·leetcode·职场和发展·动态规划