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

  Case assignment from business ethics:

Case Assignment from Business Ethics: Ethical Decision Making and Cases. You will answer the questions at the end of the case in 4 full-5 full pages (double spaced), which does not include the title or reference pages. The Case Assignments must be wr..

  Component of the marketing mix

Navigate to find the page(s) on the site that illustrates each component of the marketing mix.

  Explain the adjustment process

Comment on this statement with the help of an IS-LM diagram and explain the adjustment process?

  Organizational changerecognize the influence of senior

organizational changerecognize the influence of senior executives on organizational change and discuss possible

  Traditional financial and management evaluation

Determine whether or not traditional financial and management evaluation ratios such as return on assets (ROA), return on equity (ROE).

  Ability to construct good arguments

Also, in what ways will the skill of being able to evaluate the quality of reasoning better enable you to discover what is true and to make better choices?

  Deerborn electronics scenario

You work for Deerborn Electronics, a multinational firm providing parts for mobile devices. As the project manager for the tablet division, you have been kept extremely busy. In fact, you are putting in 60 hours per week, and it is taking a toll o..

  What pay level does the fairness wage predict

What pay level does the fairness wage predict? Does the theory accurately predict organization behavior? Why, or why not

  An internal and an external growth strategy

Find the trade-offs (pros and cons) between an internal and an external growth strategy

  Managing dynamic enviroment

For this assignment, you should create a plan to hire an employee for a position within your organization to support a recent change. In this plan, you should include the following:

  Describe the four types of inventory

Describe the four types of inventory. -  With the advent of low-cost computing, do you see alternatives to the popular ABC classifications?

  Physician licensure and physician certification

what is the difference between physician licensure and physician certification?

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