Question

Linked Lists implementation on Lists Executive Summary: Linked list implementation on lists includes two parts: Data part - stores an element of the list Next part- stores link/pointer to next element You are asked to implement Lists through Linked Lists to perform basic ADT functions. Project Objective: in completing this project, you will Enhance your ability to understand Lists Familiar with the idea of linked list Enable yourself to perform Linked Lists programming skills Due Dates and Honor: This project will be due by the beginning of the class on 7/16/2018. This is an independent programming project, and it is very important that you understand and abide by the policy concerning programming projects. Remember, your personal honor and integrity is far more important than your grade on the project. Detailed Specification: Understand and run the following code. Take a snapshot of the program output. 1. tincludeciostream> using namespace std: class node public: int data; node next: class PointerList
media%2F007%2F0073e096-e897-48cd-bcbc-34
media%2F108%2F108a6c50-be12-4249-8edf-31
media%2F42c%2F42c0099b-5404-4eef-a165-f5
0 0
Add a comment Improve this question Transcribed image text
Answer #1

///modifying insert method

void insert(int preptr_value, int element)

{ //declaraing

//new node to insert

node *newptr = newnode;

newptr->data =element;

//finding position of preptr_value

if(top==NULL)//means preptr_value not in the list

{

cout<<"Error: "<<preptr_value<<" Not in the list\n";

}

else

{

//finding preptr_value position in list..

node *temp = top;

while(temp->next!=top)

{

if(temp->data==preptr_value)

{

break;//if position is found

}

}

if(temp==top)

{

if(top->data!=preptr_value)

cout<<"Error: "<<preptr_value<<" Not in the list\n";

else

{

newptr->next =top;

top = newptr;

}

}

else

{

//linking / inserting into list

newptr->next =temp->next;

temp->next = newptr;

}

}

}

//modifying remove method

void remove(int preptr_value)

{

//finding position of preptr_value

if(top==NULL)//means preptr_value not in the list

{

cout<<"Error: "<<preptr_value<<" Not in the list\n";

}

else

{

//finding preptr_value position in list..

node *temp = top;

while(temp->next!=top)

{

if(temp->data==preptr_value)

{

break;//if position is found

}

}

if(temp==top)

{

if(top->data!=preptr_value)

cout<<"Error: "<<preptr_value<<" Not in the list\n";

else

cout<<"Contains only one value...Deletion can't be done\n";

}

else

{

node *temp1 = temp->next;

temp->next= temp1->next;

delete(temp1);//deleting node..

}

}

}

Add a comment
Know the answer?
Add Answer to:
Linked Lists implementation on Lists Executive Summary: Linked list implementation on lists includes two parts: Data...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Parts B is about our linked list implementation. avvut our linked list implementation. Recall that the...

    Parts B is about our linked list implementation. avvut our linked list implementation. Recall that the declaration of a list node is. class DListNode { public int key; public DistNode previous; public DListNode next; de ollos Salon You can assume that this is an inner class within the full MyLinked List class. B. Write a method that will add a new element to the front of a doubly linked list. Assume that head and tail point to the head and...

  • c++ modify the attached unsorted linked list class into a sorted linked list class #include <iostream>...

    c++ modify the attached unsorted linked list class into a sorted linked list class #include <iostream> using namespace std; template<class T> struct Node {     T data;//data field     Node * next;//link field     Node(T data) {       this->data = data;     } }; template<class T> class linked_list{ private:       Node<T> *head,*current; public:       linked_list(){//constructor, empty linked list         head = NULL;         current = NULL;       }       ~linked_list(){         current = head;         while(current != NULL) {          ...

  • Using a doubly linked list as the underlying data structure, implement a list ADT that implements...

    Using a doubly linked list as the underlying data structure, implement a list ADT that implements the ListInterface.java found in the ProgProjTwo Eclipse project starting point for this assignment. In addition to the forward iterator defined by resetIterator( ) and getNextItem( ) in ListInterface.java, implement a backwards iterator by providing resetBackIterator( ) and getPreviousItem( ) methods. As noted in the syllabus addendum, you are encouraged to develop a find( ) helper method that can support various list ADT operations. A...

  • Q) Modify the class Linked List below to make it a Doubly Linked List. Name your...

    Q) Modify the class Linked List below to make it a Doubly Linked List. Name your class DoublyLinkedList. Add a method addEnd to add an integer at the end of the list and a method displayInReverse to print the list backwards. void addEnd(int x): create this method to add x to the end of the list. void displayInReverse(): create this method to display the list elements from the last item to the first one. Create a main() function to test...

  • Implement the stack queue data structure with a linked list implementation to get the given test...

    Implement the stack queue data structure with a linked list implementation to get the given test code in driver.cpp to work properly: driver.cpp code: #include <iostream> #include "stackLL.h" using namespace std; int main() { /////////////Test code for stack /////////////// stackLL stk; stk.push(5); stk.push(13); stk.push(7); stk.push(3); stk.push(2); stk.push(11); cout << "Popping: " << stk.pop() << endl; cout << "Popping: " << stk.pop() << endl; stk.push(17); stk.push(19); stk.push(23); while( ! stk.empty() ) { cout << "Popping: " << stk.pop() << endl; }...

  • Given a singly-linked list interface and linked list node class, implement the singly-linked list which has...

    Given a singly-linked list interface and linked list node class, implement the singly-linked list which has the following methods in Java: 1. Implement 3 add() methods. One will add to the front (must be O(1)), one will add to the back (must be O(1)), and one will add anywhere in the list according to given index (must be O(1) for index 0 and O(n) for all other indices). They are: void addAtIndex(int index, T data), void addToFront(T data), void addToBack(T...

  • Instructions Part 1 - Implementation of a Doubly Linked List Attached you will find the code for ...

    Instructions Part 1 - Implementation of a Doubly Linked List Attached you will find the code for an implementation of a Singly Linked List. There are 3 files: Driver.java -- testing the List functions in a main() method. LinkNode.java -- Class definition for a Node, which is the underlying entity that stores the items for the linked list. SinglyLinkedList.java -- Class definition for the Singly Linked List. All the heavy lifting happens here. Task 1 - Review & Testing: Create...

  • Instructions Part 1 - Implementation of a Doubly Linked List Attached you will find the code...

    Instructions Part 1 - Implementation of a Doubly Linked List Attached you will find the code for an implementation of a Singly Linked List. There are 3 files: Driver.java -- testing the List functions in a main() method. LinkNode.java -- Class definition for a Node, which is the underlying entity that stores the items for the linked list. SinglyLinkedList.java -- Class definition for the Singly Linked List. All the heavy lifting happens here. Task 1 - Review & Testing: Create...

  • I RE: Singly Linked List, Stack, and Queue Implementation Suppose, you have the following Node clas....

    I RE: Singly Linked List, Stack, and Queue Implementation Suppose, you have the following Node clas. public class Node ! int id; Node next: public Node (int id) ( this.id id: Write program codes for the traditional: 1) append int id), prepend(int id), removeFirstNodeO. displayAlINodesO, and findById(int id) operations for a singly linked list 2) pushint id), pop), peek0, displayAllNodes0 operations for a stack 3) enQueue(int id), deQueuel), displayAINodes() operations for a gueue Please make sure that you declare separate...

  • Data Structures and Algorithms (Java Programming) a) When devising an algorithm for linked lists, why must...

    Data Structures and Algorithms (Java Programming) a) When devising an algorithm for linked lists, why must you be careful about the order in which you change the references? b) What code would be needed to change the references in a linked list when moving up one node? c) Why did we have a previous reference in our linked list implementation? d) Write a class for a linked list node with just one constructor that allows the initialization of all instance...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT