
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question

Transcribed Image Text:CSE225L – Data Structures and Algorithms Lab
Lab 11
Sorted List (linked list based)
In today's lab we will design and implement the List ADT where the items in the list are sorted.
sortedtype.h
template <class ItemType>
void SortedType<ItemType>::InsertItem (ItemType item)
#ifndef SORTEDTYPE_H_INCLUDED
NodeType* newNode;
NodeType* predLoc;
NodeType* location;
bool moreToSearch;
#define SORTEDTYPE H INCLUDED
template <class ItemType>
class SortedType
location = list Data;
struct NodeType
predLoc = NULL;
moreToSearch = (location != NULL);
ItemType info;
NodeType* next;
while (moreToSearch)
if (location->info < item)
public:
SortedType ();
-SortedType ();
bool IsFul1();
int LengthIs ();
void MakeEmpty ();
void RetrieveItem (ItemTypes,
predLoc = location;
location = location->next;
moreToSearch = (location != NULL);
else moreToSearch = false;
bool&);
newNode = new NodeType;
void InsertItem (ItemType);
void DeleteItem (ItemType);
void ResetList ();
void GetNextItem (ItemType&);
private:
NodeType* list Data;
int length;
NodeType* currentPos;
newNode->info = item;
if (predLoc == NULL)
newNode->next = list Data;
listData = newNode;
else
newNode->next = location;
#endif // SORTEDTYPE H_ INCLUDED
sortedtype.cpP
predLoc->next = newNode;
length++;
#include "sortedtype.h"
tinclude <iostream>
using namespace std;
template <class ItemType>
void SortedType<ItemType>: : DeleteItem (ItemType item)
template <class ItemType>
SortedType<ItemType>: : SortedType ()
NodeType* location = listData;
NodeType* tempLocation;
if (item == listData->info)
length = 0;
list Data - NULL;
currentPos = NULL;
tempLocation = location;
listData = listData->next;
else
template <class ItemType>
int SortedType<ItemType>: :LengthIs ()
while (! (item== (location->next)->info))
location = location->next;
return length;
tempLocation = location->next;
location->next = (location->next)->next;
template<class ItemType>
bool SortedType<ItemType>::IsFull ()
delete templocation;
length--;
NodeType* location;
try
location = new NodeType;
delete location;
return false;
catch (bad_allocs exception)
return true;

Transcribed Image Text:template <class ItemType>
void
template <class ItemType>
SortedType<ItemType>::-SortedType ()
SortedType<ItemType>: :RetrieveItem (ItemType
& item, bool& found)
MakeEmpty ();
{
NodeType* location
bool moreToSearch = (location != NULL);
= listData;
template <class ItemType>
void SortedType<ItemType>::ResetList ()
{
current Pos = NULL;
%3D
found = false;
while (moreToSearch && !found)
{
if (item == location->info)
found = true;
template <class ItemType>
void
SortedType<ItemType>::GetNextItem (ItemType
& item)
else if (item > location->info)
location = location->next;
moreToSearch = (location !=
{
if (currentPos == NULL)
currentPos = listData;
NULL);
else
else
moreToSearch = false;
currentPos = current Pos->next;
item = currentPos->info;
template <class ItemType>
void SortedType<ItemType>: :MakeEmpty ()
{
NodeType* tempPtr;
while (listData != NULL)
{
tempPtr = listData;
listData - listData->next;
delete tempPtr;
length = 0;
Generate the driver file (main.cpp) where you perform the following tasks. Note that you cannot make any change to
the header file or the source file.
Operation to Be Tested and Description of Action
|Input Values
Expected Output
Write a class timeStamp that represents a time of the
day. It must have variables to store the number of
seconds, minutes and hours passed. It also must have a
function to print all the values. You will also need to
overload a few operators.
Create a list of objects of class timestamp.
• Insert 5 time values in the format ssmmhh
15 34 23
13 13 02
43 45 12
25 36 17
52 02 20
Delete the timestamp 25 36 17
15:34-23
13:13:02
43:45:12
52:02:20
• Print the list
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- a class named as MyDeque y function add to head and add last functi g linked list aTd make a separate class andarrow_forwardThere are many benefits of this data structure over others like linked lists and trees.arrow_forwardASSUMING C LANGUAGE True or False: You can have the data portion of a Linked List be a Struct containing a Linked List itselfarrow_forward
- What is the biggest advantage of linked list over array? Group of answer choices Unlike array, linked list can dynamically grow and shrink With linked list, it is faster to access a specific element than with array Linked list is easier to implement than array Unlike array, linked list can only hold a fixed number of elementsarrow_forwardComputer Science lab3.h ------------- #include<stdio.h> #include<stdlib.h> #ifndef LAB3_H #define LAB3_H // A linked list node struct Node { int data; //Data struct Node *next; // Address to the next node }; //initialize: create an empty head node (whose "data" is intentionally missing); This head node will not be used to store any data; struct Node *init () { //create head node struct Node *head = (struct Node*)malloc(sizeof(struct Node)); } //Create a new node to store data and insert it to the end of current linked list; the head node will still be empty and data in the array in "main.c" are not stored in head node void insert(struct node *head, int data) { struct Node *newNode = (struct Node*)malloc(sizeof(struct Node)); new_node->data = data; new_node->next= head; } //print data for all nodes in the linked list except the head node (which is empty) void display (struct Node *head) { struct Node *current_node = head; while ( current_node != NULL) { printf("%d ",…arrow_forwardUsing Fundamental Data Structures Purpose: The purpose of this: Design and develop Applications that incorporate fundamental data structures such as: Singly Linked Lists Doubly Linked Lists Circularly Linked Lists Exercise 3 If your first name starts with a letter from A-J inclusively: Implement the clone() method for the CircularlyLinkedList class. Make sure to properly link the new chain of nodes. If your first name starts with a letter from K-Z inclusively: Let L1 and L2 be two circularly linked lists created as objects of CircularlyLinkedList class from Lesson. Write a method that returns true if L1 and L2 store the same sequence of elements (but perhaps with different starting points). Write the main method to test the new method. Hint: Try to find a matching alignment for the first node of one list.arrow_forward
- C++The List class represents a linked list of dynamically allocated elements. The list has only one member variable head which is a pointer that leads to the first element. See the following code for the copy constructor to List. List (const List & list) { for (int i = 0; i <list.size (); i ++) { push_back (list [i]); } } What problems does the copy constructor have? Select one or more options: 1. List (const List & list) {} does not define a copy constructor. 2. The list parameter should not be constant. 3. The new elements will be added to the wrong list. 4. Copy becomes shallow rather than deep. 5. The copy will create dangling pointers. 6. Copying will create memory leaks. 7. The condition must be: i <size () 8. head is never initialized.arrow_forwardProject 2: Singly-Linked List The purpose of this assignment is to assess your ability to: ▪Implement sequential search algorithms for linked list structures ▪Implement sequential abstract data types using linked data ▪Analyze and compare algorithms for efficiency using Big-O notation For this assignment, you will implement a singly-linked node class. Use your singly-linked node to implement a singly-linked list class that maintains its elements in ascending order. The SinglyLinkedList class is defined by the following data: ▪A node pointer to the front and the tail of the list Implement the following methods in your class: ▪A default constructor list<T> myList ▪A copy constructor list<T> myList(aList) ▪Access to first elementmyList.front() ▪Access to last elementmyList.back() ▪Insert value myList.insert(val) ▪Remove value at frontmyList.pop_front() ▪Remove value at tailmyList.pop_back() ▪Determine if emptymyList.empty() ▪Return # of elementsmyList.size() ▪Reverse order of…arrow_forwardDSarrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education