99爱在线视频这里只有精品_窝窝午夜看片成人精品_日韩精品久久久毛片一区二区_亚洲一区二区久久

合肥生活安徽新聞合肥交通合肥房產(chǎn)生活服務(wù)合肥教育合肥招聘合肥旅游文化藝術(shù)合肥美食合肥地圖合肥社保合肥醫(yī)院企業(yè)服務(wù)合肥法律

代做CSCI 241 Data Structures

時間:2024-03-06  來源:合肥網(wǎng)hfw.cc  作者:hfw.cc 我要糾錯


CSCI 241 Data Structures

Project 2: Literally Loving Linked Lists LOL

In this project, you will implement a sentineled doubly-linked list. Recall that a linked list is composed of Node objects that are linked together. This means that we will need to create two classes in this implementation. One class will represent the Nodes of data and how they are linked together. The other class will represent the actual Linked List, defining methods for adding and removing elements, creating a string representation of the object, and obtaining its length.

We have discussed a variety of methods for inserting and removing values in a linked list. This project will use index-based addressing. Recall from our studies of arrays that index zero identifies the location of the first datum. This approach also means that the maximum valid index is one less than the length of the sequence. We will replicate that indexing paradigm here. Note that index zero identifies the first Node object that contains data, and not the header. Neither the header nor the trailer has an index.

Your implementation should support the following methods, keeping in mind that the words index, head, and tail are used descriptively only and should not appear as attributes of either class. For methods that take indices as parameters, you should start at the sentinel node closest to the provided index when moving the required location in the list.

append_element(self, val) This method should increase the size of the list by one, adding the specified value in the new tail position. This is the only way to add a value as the tail.

insert_element_at(self, val, index) If the provided index identifies a valid zero-based position within the list, then insert the specified value at that position, increasing the length by one. This method can be used to insert at the head of a non-empty list, but cannot append to a list.

The provided index must be within the current bounds of the list. If the index is not valid, raise an IndexError exception.

remove_element_at(self, index) If the provided index identifies a valid zero-based position within the list, then remove and return the value stored in a Node at that position. If the index is not valid, raise an IndexError exception.

get_element_at(self, index) If the  provided  index identifies a valid zero-based position within the list, then obtain the value from the Node at that position and return it. Do not unlink the Node object. If the index is not valid, raise an IndexError exception.

rotate_left(self) Without constructing any  new  node  objects  and without returning anything, rotate the list left so that each node moves one position earlier than it was and the original head becomes the new

tail. The length of the list should not change. If the list is empty, this method has no effect.

__len__(self) Return the number of values currently stored in the list. Python will automatically call this function when a Linked_List object is passed to the globally defined len() function.

__str__(self) Return  a string representation of the values currently stored in the list. An empty list should appear as [ ] (note the single space). A list with one integer object should appear as [ 5 ] (note the spaces inside the brackets). A list with two integer objects should appear as [ 5, 7 ], and so on. Pay close attention to the format of this string, and remember that strings can be concatenated with the + operator. To convert other objects to strings, use str(other_object). As long as the class  for  the  other  object  implements  the  __str__() method,  this approach will work. Python will automatically call this function when a Linked_List object is passed to the globally defined str() function. A linear-time solution to this method is possible, but challenging. If your implementation  performs  in  linear  time,  a  small  score  bonus  will awarded.

__iter__(self) See "Iterators" below. Python will automatically call this function when a Linked_List object appears after the keyword in in a for loop declaration

__next__(self) See "Iterators" below. Note that this method is different from the next attribute of the __Node class.

__reversed__(self) Construct a new Linked_List object and populate it with aliases to the same value objects referenced in the nodes of this list, but in reverse order. Calling this method has no effect on this list; it only constructs and returns a new list. To ensure that this method operates in linear time, use the prev attribute of the nodes to work from the tail position to the head position. Python will automatically call this function when a Linked_List object is passed to the globally defined reversed() function.

Exceptions

In lecture, we have silently ignored bad method calls (such as requesting the value of an index that is equal to or greater than the length of the list) by detecting that condition at the beginning of the method and returning. In practice, it is better to inform the programmer that her request was invalid, and allow her to handle the problem. The mechanisms for achieving this are called exceptions and try blocks. When you detect an error condition, instead of returning,  raise the appropriate exception using the syntax

raise ExceptionName

When the programmer calls a method that could potentially generate an exception, she does so in what we call a try block. Suppose she calls a method that could raise a ValueError. Her code to invoke that method would have to look like this:

my_object = Awesome_Class()

try:

asplode = random.randint(1,10)

my_object.dangerous_call(asplode)

print("whew... made it.")

except ValueError:

print("**>_KABOOM_<**")

print("on the other side.")

Perhaps the dangerous_call(num) method raises a ValueError if the value of num is 5, and raises no exception otherwise. Because asplode is equally likely to be one of ten values (one through ten, inclusive) in the example above, she will get with **% probability

whew... made it.

on the other side.

or with 10% probability (when asplode is the one of ten possible values, the value 5, that is problematic)

**>_KABOOM_<**

on the other side.

Each method in your Linked List class that takes an index as a parameter should raise an IndexError (this type is built-in to Python) if the provided index is out of bounds. For our implementation, indices that are either too large or negative should be considered out-of-bounds. No other exceptions types are specified for this project.

Inner Classes

One thing that we have mentioned briefly during lecture that is relevant to this project is the concept of inner classes. We already know that the Linked List implementation will employ objects of a Node class, so these two classes will be working together. An important point, though, is that the end user of the Linked List doesn't actually see Nodes. Think back to arrays for a moment; when you use an array, you don't actually  see  the  cells  that  store  the  data.  You  see  and  interact  with  the  data themselves. The same will  be true for  Linked  Lists.  The  person  using  your  list implementation doesn't actually care about Nodes. All she cares about is that her data are stored in the list. Because of this, it is not necessary (or even desirable) for the Node class to be exposed to the world. It should only be used internally by the Linked List implementation methods. When a user inserts data into the list, she provides the data as an object of whatever type she is storing. If she is dealing with integers, she will insert the number 5, not a Node containing the number 5. The use

of a Node object to encapsulate the value 5 is completely internal to the Linked List and is never exposed.

To help provide this encapsulation, your solution should implement the Node class itself as a private member of the Linked List class. By marking the class private (with leading underscores) and implementing it inside of the Linked List class, we indicate that it should only be used internally to Linked Lists. The concept is similar to private attributes,  but  instead  of  being  declared  as  self.__attr_name inside  of  the constructor, the inner class is defined at the same level as the methods. Note the discussion later in this specification about transitivity of privacy —the attributes of your __Node class must be public with no leading underscores.

Iterators

Using the method get_element_at(index), we could visit every node in the list by looping through all of the valid indices. The problem with that approach is that instead of   linear    time   performance,    we    have   quadratic    time.   Notice    that   the get_element_at(index) method is linear. It must do a current-walk to reach position index, which is at the tail position in the worst case. Retrieving the first element will take 1 step; retrieving the second element will take 2 steps. You should recognize this pattern from our analysis of insertion sort. The sum of  consecutive integers beginning at 1 is bounded by 2 . Considering how frequently we use loops to visit every value in a sequence, quadratic performance is not desirable.

To keep the time linear as expected, we employ a programming structure called an iterator. You have used iterators many times. Consider the following code segment:

arr = [5,2,-4,1]

for val in arr:

print(str(val))

The loop iterates through the values in the array. When Python encounters the loop, it initializes an index for the array. On every entrance of the loop, it assigns val the value contained at that index, then increments the index. When the index reaches the length of the array, the iteration terminates.

You can replicate this behavior for any class you write by implementing two special methods: __iter__(self) and __next__(self). Analogous to the code segment above is the following version that uses a linked list object instead of an array:

ll = Linked_List()

ll.append_element(5)

ll.append_element(2)

ll.append_element(-4)

ll.append_element(1)

for val in ll:

print(str(val))

Right before the for loop, the object ll should contain the elements 5, 2, -4, and 1. When Python encounters the for loop, it invokes the __iter__() method on the ll object (after the keyword in). This is Python’s way of telling the ll object to prepare to cycle through its elements. In your __iter__() method, you should initialize a current pointer in preparation for walking the list. Each time  Python enters the indented for block, it assigns val whatever is returned by a hidden call to __next__(). In your __next__() method, you should decide whether there is another value to return. If so, advance to the node whose value should be returned and return that value. If not, raise a StopIteration exeption. Python will automatically handle the exception as a signal to stop calling your __next__() method. This terminates the for loop.

Below is the skeleton implementation that you will complete. The Python file attached to this assignment contains comments describing each method. Supplement those comments  with  a  performance  analysis  for  each  method.  State  the  big-oh performance and offer a **2 sentence explanation of why that stated performance is correct.

class Linked_List:

class __Node:

def __init__(self, val):

def __init__(self):

def __len__(self):

def __iter__(self):

def __next__(self):

def append_element(self, val):

def insert_element_at(self, val, index):

def remove_element_at(self, index):

def get_element_at(self, index):

def rotate_left(self):

def __str__(self):

if __name__ == '__main__':

Most importantly, notice that the Node class is defined within the Linked List class and is private to that class. This means that only the methods inside of the Linked List implementation have access to Nodes; they are not exposed to the user. It also

means that to create a new node inside of an insert method, the syntax is

new_node = Linked_List.__Node(my_val)

Then, new_node is a Node object that can be linked in at the appropriate location. In most object-oriented languages, outer classes have access to the private members of inner classes. This is not true in Python, so we must make the Node attributes public. Alternatively, we could add accessor and mutator methods to the Node class, but that would add significant overhead given the frequency of node references. Even though we make the Node attributes public, the nodes themselves can only be referenced from the Linked List methods, because the very concept of what a Node is is private to the Linked List class.

In the main section of your Python file, provide some test cases to ensure that your Linked List implementation functions correctly. Though this is not an exhaustive list, some things to consider are:

•    Does appending to the list add an element at the new tail position and increment the size by one?

•    Does inserting an item at a valid index increase the size by one and correctly modify the list's structure?

•    Does inserting an item at an invalid index leave the list completely unchanged?

•    Does removing an item at a valid index decrease the size by one and correctly modify the list's structure?

•    Does removing an item at an invalid index leave the list completely unchanged?

•    Does length always return the number of values stored in the list (not including sentinel nodes)?

•    Is the string representation of your list correct for a variety of lengths?

•    Does a for loop like

for val in my_list

visit every value in original order?

•    Does a for loop like

for val in reversed(my_list)

visit every value in reverse order?

Submission Expectations

1.  Linked_List.py:   A   file   containing   your   completed    Linked   List   class implementation, including comments about performance. Though you are free to add additional methods as you deem necessary, you must not change the names (including spelling) or parameter lists of any methods in the skeleton file. The main section at the bottom of this file must contain your testing code, which should be significant in length and complexity. Do not identify yourself anywhere in the file.
請加QQ:99515681  郵箱:99515681@qq.com   WX:codehelp 

掃一掃在手機(jī)打開當(dāng)前頁
  • 上一篇:代寫CSCE 240 – Programming
  • 下一篇:代寫SEHS4517、SQL編程語言代做
  • 無相關(guān)信息
    合肥生活資訊

    合肥圖文信息
    急尋熱仿真分析?代做熱仿真服務(wù)+熱設(shè)計優(yōu)化
    急尋熱仿真分析?代做熱仿真服務(wù)+熱設(shè)計優(yōu)化
    出評 開團(tuán)工具
    出評 開團(tuán)工具
    挖掘機(jī)濾芯提升發(fā)動機(jī)性能
    挖掘機(jī)濾芯提升發(fā)動機(jī)性能
    海信羅馬假日洗衣機(jī)亮相AWE  復(fù)古美學(xué)與現(xiàn)代科技完美結(jié)合
    海信羅馬假日洗衣機(jī)亮相AWE 復(fù)古美學(xué)與現(xiàn)代
    合肥機(jī)場巴士4號線
    合肥機(jī)場巴士4號線
    合肥機(jī)場巴士3號線
    合肥機(jī)場巴士3號線
    合肥機(jī)場巴士2號線
    合肥機(jī)場巴士2號線
    合肥機(jī)場巴士1號線
    合肥機(jī)場巴士1號線
  • 短信驗證碼 豆包 幣安下載 AI生圖 目錄網(wǎng)

    關(guān)于我們 | 打賞支持 | 廣告服務(wù) | 聯(lián)系我們 | 網(wǎng)站地圖 | 免責(zé)聲明 | 幫助中心 | 友情鏈接 |

    Copyright © 2025 hfw.cc Inc. All Rights Reserved. 合肥網(wǎng) 版權(quán)所有
    ICP備06013414號-3 公安備 42010502001045

    99爱在线视频这里只有精品_窝窝午夜看片成人精品_日韩精品久久久毛片一区二区_亚洲一区二区久久

          9000px;">

                亚洲国产精品久久人人爱蜜臀| 夜夜亚洲天天久久| 亚洲精品欧美激情| 欧美日韩一区二区三区视频| 亚洲bt欧美bt精品| 精品粉嫩超白一线天av| 国产乱码字幕精品高清av| 国产日韩欧美一区二区三区综合| 国产在线播放一区三区四| 亚洲欧洲一区二区在线播放| 日本高清不卡在线观看| 五月婷婷综合激情| 久久久久九九视频| 欧美中文字幕一区二区三区| 蜜臀av性久久久久蜜臀aⅴ| 久久综合视频网| 欧美怡红院视频| 九九精品视频在线看| 亚洲欧美一区二区三区久本道91 | 成人免费高清在线| 亚洲综合久久久久| 久久综合九色综合97婷婷| 欧美在线观看你懂的| 国产精品一区久久久久| 亚洲一区二区五区| 欧美国产精品中文字幕| 日韩欧美二区三区| 91传媒视频在线播放| 大陆成人av片| 久久99精品国产麻豆不卡| 一区二区三区国产精华| 久久精品综合网| 日韩一区二区三区在线视频| 色婷婷精品久久二区二区蜜臀av | 亚洲欧美另类久久久精品2019| 91精品婷婷国产综合久久 | 精品捆绑美女sm三区| 色综合一个色综合亚洲| 国产黄色精品网站| 国产一区二区三区在线观看免费| 亚洲欧洲美洲综合色网| 久久精品日韩一区二区三区| 欧美精选午夜久久久乱码6080| av动漫一区二区| 国产精品一区二区在线播放| 奇米影视一区二区三区小说| 亚洲国产精品精华液网站| 日韩伦理电影网| 亚洲欧洲精品成人久久奇米网| 国产欧美日韩不卡| 国产调教视频一区| 国产清纯美女被跳蛋高潮一区二区久久w| 成人深夜福利app| 成人影视亚洲图片在线| 成人久久视频在线观看| av不卡免费在线观看| 97se亚洲国产综合在线| eeuss鲁一区二区三区| 99精品久久只有精品| 一本在线高清不卡dvd| 一本一道综合狠狠老| 欧美亚洲日本一区| 日韩一区二区三区电影在线观看| 欧美日韩精品免费| 精品国产乱码久久久久久免费| 久久影音资源网| 欧美激情自拍偷拍| 亚洲视频 欧洲视频| 亚洲精品国产精品乱码不99| 亚洲午夜成aⅴ人片| 日韩精品国产精品| 国产中文字幕一区| 91丨九色porny丨蝌蚪| 欧美日韩中字一区| 久久久国产精品麻豆| 1024国产精品| 亚洲成av人**亚洲成av**| 美洲天堂一区二卡三卡四卡视频| 国产精品亚洲人在线观看| 99精品偷自拍| 91精品国产综合久久久久久久| 日韩精品一区二区三区四区| 国产欧美日韩另类一区| 一区二区理论电影在线观看| 天堂一区二区在线免费观看| 国模娜娜一区二区三区| 色狠狠综合天天综合综合| 日韩欧美国产1| 国产精品国产a| 亚洲一区二区三区四区五区中文| 精品一区在线看| 91国产精品成人| 国产肉丝袜一区二区| 日韩国产在线观看一区| 色综合视频一区二区三区高清| 91精品黄色片免费大全| 综合激情成人伊人| 九九**精品视频免费播放| 在线免费观看日本欧美| 国产视频在线观看一区二区三区| 亚洲综合自拍偷拍| 成人免费视频一区二区| 日韩免费观看高清完整版在线观看| 亚洲天堂福利av| 国产裸体歌舞团一区二区| 欧洲一区二区三区免费视频| 久久精品视频在线看| 免费在线视频一区| 欧美日韩亚洲综合在线 欧美亚洲特黄一级 | 国产精品一线二线三线精华| 色噜噜狠狠成人中文综合 | 国产精品影视在线观看| 欧美老肥妇做.爰bbww视频| 中文字幕一区二区三区四区 | 激情欧美一区二区| 91精品国产综合久久福利| 国产精品久久久久久久久晋中 | 色妞www精品视频| 久久精品欧美日韩| 九一久久久久久| 日韩欧美一区电影| 日韩电影一二三区| 91精品国产综合久久福利| 亚洲va中文字幕| 欧美伊人久久大香线蕉综合69| 亚洲人成在线播放网站岛国| 成人激情黄色小说| 国产欧美视频一区二区| 国产精品69毛片高清亚洲| 久久精品日韩一区二区三区| 国产jizzjizz一区二区| 久久久99精品久久| 国产乱对白刺激视频不卡| 精品国产伦一区二区三区免费 | 1024成人网| 99久久精品免费看国产| 中文字幕人成不卡一区| 91蜜桃婷婷狠狠久久综合9色| 国产精品久久久久久久久果冻传媒| 成人国产免费视频| 亚洲婷婷综合色高清在线| 日本韩国欧美一区二区三区| 亚洲国产人成综合网站| 欧美精品乱码久久久久久按摩| 日本免费新一区视频 | 国产精品一区二区久久不卡| 精品国产在天天线2019| 成人免费观看男女羞羞视频| 最近中文字幕一区二区三区| 欧美日韩一区在线观看| 老司机精品视频一区二区三区| 国产亚洲欧洲997久久综合| av色综合久久天堂av综合| 亚洲资源在线观看| 欧美va亚洲va香蕉在线| 99综合电影在线视频| 香蕉影视欧美成人| 久久尤物电影视频在线观看| 91免费小视频| 久久91精品久久久久久秒播 | 国产精品欧美久久久久无广告| 色8久久人人97超碰香蕉987| 婷婷亚洲久悠悠色悠在线播放| 久久久久久久久久久电影| 91尤物视频在线观看| 青青草视频一区| 亚洲欧美中日韩| 欧美一区二区三区婷婷月色| kk眼镜猥琐国模调教系列一区二区| 天天色综合成人网| 成人欧美一区二区三区小说| 日韩视频在线你懂得| 成人美女视频在线观看18| 久久er99精品| 亚洲电影欧美电影有声小说| 中文字幕国产一区| 欧美电影免费观看高清完整版在线 | 欧美视频一区在线| 国产成人精品三级麻豆| 三级影片在线观看欧美日韩一区二区| 欧美xxxxx牲另类人与| 色婷婷精品久久二区二区蜜臂av | 亚洲精品日日夜夜| 久久综合九色综合久久久精品综合| 色婷婷av一区二区三区大白胸| 九色|91porny| 日本欧美一区二区三区乱码| 一区二区三区国产精华| 18涩涩午夜精品.www| 国产亚洲精品中文字幕| 日韩欧美成人午夜| 8x8x8国产精品| 欧美私人免费视频| 在线区一区二视频| 欧美无人高清视频在线观看| 91蝌蚪porny| 99久精品国产| 91亚洲精品一区二区乱码| 成人国产精品免费网站| 国产69精品久久久久777|