0% found this document useful (0 votes)
133 views

In Today's Lab We Will Design and Implement The List ADT Where The Items in The List Are Unsorted

This lab covers implementing an unsorted list data structure using arrays. The document provides header and source code for an UnsortedType class template that defines list operations like insertion, deletion, retrieval and traversal. It also provides test cases to test the list implementation using integers and a student record class.

Uploaded by

Peter Rabbit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
133 views

In Today's Lab We Will Design and Implement The List ADT Where The Items in The List Are Unsorted

This lab covers implementing an unsorted list data structure using arrays. The document provides header and source code for an UnsortedType class template that defines list operations like insertion, deletion, retrieval and traversal. It also provides test cases to test the list implementation using integers and a student record class.

Uploaded by

Peter Rabbit
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

CSE225L – Data Structures a nd Alg o rithms Lab

Lab 04
Unsorted List (array based)

In today’s lab we will design and implement the List ADT where the items in the list are unsorted.

unsortedtype.h template <class ItemType>


void
#ifndef UNSORTEDTYPE_H_INCLUDED UnsortedType<ItemType>::RetrieveItem(ItemType&
#define UNSORTEDTYPE_H_INCLUDED item, bool &found)
{
const int MAX_ITEMS = 5; int location = 0;
bool moreToSearch = (location < length);
template <class ItemType> found = false;
class UnsortedType while (moreToSearch && !found)
{ {
public : if(item == info[location])
UnsortedType(); {
void MakeEmpty(); found = true;
bool IsFull(); item = info[location];
int LengthIs(); }
void InsertItem(ItemType); else
void DeleteItem(ItemType); {
void RetrieveItem(ItemType&, bool&); location++;
void ResetList(); moreToSearch = (location < length);
void GetNextItem(ItemType&); }
private: }
int length; }
ItemType info[MAX_ITEMS]; template <class ItemType>
int currentPos; void UnsortedType<ItemType>::InsertItem(ItemType
}; item)
#endif // UNSORTEDTYPE_H_INCLUDED {
info[length] = item;
unsortedtype.cpp length++;
}
#include "UnsortedType.h" template <class ItemType>
void UnsortedType<ItemType>::DeleteItem(ItemType
template <class ItemType> item)
UnsortedType<ItemType>::UnsortedType() {
{ int location = 0;
length = 0; while (item != info[location])
currentPos = -1; location++;
} info[location] = info[length - 1];
template <class ItemType> length--;
void UnsortedType<ItemType>::MakeEmpty() }
{
length = 0;
}
template <class ItemType>
bool UnsortedType<ItemType>::IsFull()
{
return (length == MAX_ITEMS);
}
template <class ItemType>
int UnsortedType<ItemType>::LengthIs()
{
return length;
}
template <class ItemType>
void UnsortedType<ItemType>::ResetList()
{
currentPos = -1;
}
template <class ItemType>
void
UnsortedType<ItemType>::GetNextItem(ItemType&
item)
{
currentPos++;
item = info [currentPos] ;
}
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


• Create a list of integers
•• Insert four items 5 7 6 9
• Print the list 5769
• Print the length of the list 4
• Insert one item 1
• Print the list 57691
• Retrieve 4 and print whether found or not Item is not found
• Retrieve 5 and print whether found or not Item is found
• Retrieve 9 and print whether found or not Item is found
• Retrieve 10 and print whether found or not Item is not found
• Print if the list is full or not List is full
• Delete 5
• Print if the list is full or not List is not full
• Delete 1
• Print the list 769
• Delete 6
• Print the list 79
• Write a class studentInfo that represents a student
record. It must have variables to store the student ID,
student’s name and student’s CGPA. 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 studentInfo.
• Insert 5 student records 15234 Jon 2.6
13732 Tyrion 3.9
13569 Sandor 1.2
15467 Ramsey 2 3.1
16285 Arya 3.1
• Delete the record with ID 15467
• Retrieve the record with ID 13569 and print whether Item is found
found or not along with the entire record 13569, Sandor, 1.2
• Print the list 15234, Jon, 2..6
13732, Tyrion, 3.9
13569, Sandor, 1.2
16285, Arya, 3.1

You might also like