Linked list delete element problem

Assignment Help Business Management
Reference no: EM131981395

Linked List Delete Element Problem

Implement a method, remove_first which takes a linked list as a parameter and removes the first element. Make sure to check all possible cases for the possible sizes of the linked list. Use assert statement(s). 

def remove_first(s):

  ''' Removes the first node in the given list

  >>> remove_first(link(4,link(3, link(2, link(1, 'empty')))))

  [3, [2, [1, 'empty']]]

  >>> remove_first(link(1, 'empty'))

  'empty'

  '''

  "*** YOUR CODE HERE ***"

Implement a method, remove_last which takes a linked list as a parameter and removes the last element. Make sure to check all possible cases for the possible sizes of the linked list. Use assert statement(s). 

def remove_last(s):

  ''' Removes the last node in the given list

  >>> remove_last(link(4,link(3, link(2, link(1, 'empty')))))

  [4, [3, [2, 'empty']]]

  >>> remove_last(link(1, 'empty'))

  'empty'

  '''

  "*** YOUR CODE HERE ***"

Implement delete_at which takes a linked-list, and a deletion index and returns the reconstructed list with the element at the given location removed.

def delete_at(s, idx):

  '''Delete element in a given list at provided index.

    Please fill in the provided assert statements and do not

    modify the printed msg.

  >>> lst = link(3, link(2, link(1, empty)))

  >>> delete_at(lst, 0)

  [2, [1, 'empty']]

  >>> delete_at(lst, 2)

  [3, [2, 'empty']]

  '''

  "*** YOUR CODE HERE ***"

IMPORTANT Information:

empty = 'empty'

def is_link(s):

  """s is a linked list if it is empty or a (first, rest) pair."""

  return s == empty or (len(s) == 2 and is_link(s[1]))

def link(first, rest):

  """Construct a linked list from its first element and the rest."""

  assert is_link(rest), "rest must be a linked list."

  return [first, rest]

def first(s):

  """Return the first element of a linked list s."""

  assert is_link(s), "first only applies to linked lists."

  assert s != empty, "empty linked list has no first element."

  return s[0]

def rest(s):

  """Return the rest of the elements of a linked list s."""

  assert is_link(s), "rest only applies to linked lists."

  assert s != empty, "empty linked list has no rest."

  return s[1]

# define length

def len_link(s):

  """Return the length of linked list s."""

  length = 0

  while s != empty:

    s, length = rest(s), length + 1

  return length

# getitem

def getitem(s, i):

  """Return the element at index i of linked list s."""

  while i > 0:

    s, i = rest(s), i - 1

  return first(s)

Reference no: EM131981395

Questions Cloud

Compare the positive and negative aspects of dac and rbac : Compare the positive and negative aspects of employing a MAC, DAC, and RBAC. Suggest methods to mitigate the negative aspects for MAC, DAC, and RBAC.
Linked list insert element problem : Implement a method, insert_first which takes a linked list as a parameter and elem, and returns a new list, where elem was inserted as a first node.
Discuss about the relationship between business and society : Prepare and present a video that is a maximum of five to seven (5-7) minutes OR write a four to six (4-6) page paper in which you:
What internal policies do you plan to implement : What internal policies do you plan to implement based on evidence-based practice approaches to ensure your organization meets these standards?
Linked list delete element problem : Implement a method, remove_first which takes a linked list as a parameter and removes the first element. Make sure to check all possible cases
Calculate the firm return on equity : Calculate the firm return on equity. is the percentage return?
Describe the methods to mitigate the vulnerabilities : Describe the methods to mitigate the vulnerabilities, as they relate to the seven domains. Describe the impact and the vulnerability of the SCADA.
Explain the uniform computer information transactions act : Conducting business over the Internet is the new norm today, in fact many business transactions in the form of contracts are conducted over the Internet.
Are you ready to present the policies for compliance plans : Are you ready to present the policies for your two compliance plans in a way that all employees will understand at a large medical facility.

Reviews

Write a Review

Business Management Questions & Answers

  Caselet on michael porter’s value chain management

The assignment in management is a two part assignment dealing 1.Theory of function of management. 2. Operations and Controlling.

  Mountain man brewing company

Mountain Man Brewing, a family owned business where Chris Prangel, the son of the president joins. Due to increase in the preference for light beer drinkers, Chris Prangel wants to introduce light beer version in Mountain Man. An analysis into the la..

  Mountain man brewing company

Mountain Man Brewing, a family owned business where Chris Prangel, the son of the president joins. An analysis into the launch of Mountain Man Light over the present Mountain Man Lager.

  Analysis of the case using the doing ethics technique

Analysis of the case using the Doing Ethics Technique (DET). Analysis of the ethical issue(s) from the perspective of an ICT professional, using the ACS Code of  Conduct and properly relating clauses from the ACS Code of Conduct to the ethical issue.

  Affiliations and partnerships

Affiliations and partnerships are frequently used to reach a larger local audience? Which options stand to avail for the Hotel manager and what problems do these pose.

  Innovation-friendly regulations

What influence (if any) can organizations exercise to encourage ‘innovation-friendly' regulations?

  Effect of regional and corporate cultural issues

Present your findings as a group powerpoint with an audio file. In addition individually write up your own conclusions as to the effects of regional cultural issues on the corporate organisational culture of this multinational company as it conducts ..

  Structure of business plan

This assignment shows a structure of business plan. The task is to write a business plane about a Diet Shop.

  Identify the purposes of different types of organisations

Identify the purposes of different types of organisations.

  Entrepreneur case study for analysis

Entrepreneur Case Study for Analysis. Analyze Robin Wolaner's suitability to be an entrepreneur

  Forecasting and business analysis

This problem requires you to apply your cross-sectional analysis skills to a real cross-sectional data set with the goal of answering a specific research question.

  Educational instructional leadership

Prepare a major handout on the key principles of instructional leadership

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd