You are on page 1of 8

Laboratory Report 1

POINTERS, LINKED LISTS, AND STACKS


Name: Arthur Jacob V. Lintag Date: 19/9/2023
Program: CPE Section: C4

A. Instructions:
(Please include the following: 1. Screenshots of the output from MindTap, 2. Screenshots of the IDE from
MindTap, and 3. The source code from MindTap.)

Screenshot of Output
(Insert images here from the output of the console window of MindTap)

Resize the image if necessary.

Screenshot of Codes
(Insert images here)

Screenshot of your code in MindTap. Use the snipping tool to properly capture the codes.

Resize the image properly so that it fits in the table. Use a whole page for this part if necessary.

Source Code
(insert Source Code here)

Paste the actual code from MindTap here. Use the following format: Courier New 9

#include <iostream>

using namespace std;

int main() {
cout << "Hello World" << endl;
return 0;
}

_________________________________________________________________________________________________
CPE104L Data Structures and Algorithms
School of Electrical, Electronics, and Computer Engineering Page | 1
Laboratory Report 1
POINTERS, LINKED LISTS, AND STACKS

_________________________________________________________________________________________________
CPE104L Data Structures and Algorithms
School of Electrical, Electronics, and Computer Engineering Page | 2
Laboratory Report 1
POINTERS, LINKED LISTS, AND STACKS
B. Coding Exercises:
1. The function retrieveAt of the class arrayListType is written as a void function. Rewrite this function so that
it is written as a value returning function, returning the required item. If the location of the item to be returned
is out of range, use the assert function to terminate the program. Also, write a program to test your function.
Use the class unorderedArrayListType to test your function.

Screenshot of Output

Screenshot of Codes

Source Code

#include <iostream>
#include "unorderedArrayListType.h"

using namespace std;

int main() {
unorderedArrayListType Listed(8);

int num;
int location;

for (int i = 0; i < 8; i++) {


cin >> num;
Listed.insertEnd(num);
}

Listed.print();
cout << endl;

cout << "Enter Location: ";


cin >> location;

if (location >= 0 && location < Listed.listSize()) {


int retrievedItem = Listed.retrieveAt(location);
cout << "Item at location " << location << " is: " << retrievedItem << endl;
} else {
cerr << "Error: Invalid location" << endl;

return 0;
}

2. Write a program to test various operations of the class doublyLinkedList. Your program should accept a list
of integers from a user and use the doubleLinkedList class to output the following:
1. The list in ascending order.
2. The list in descending order.
3. The list after deleting a number.
4. A message indicating if a number is contained in the list.
5. Output of the list after using the copy constructor.
6. Output of the list after using the assignment operator.

Screenshot of Output

Screenshot of Codes

_________________________________________________________________________________________________
CPE104L Data Structures and Algorithms
School of Electrical, Electronics, and Computer Engineering Page | 3
Laboratory Report 1
POINTERS, LINKED LISTS, AND STACKS

Source Code

#include <iostream>
#include "doublyLinkedList.h"
using namespace std;
void TCC(doublyLinkedList<int> list);
int main() {
doublyLinkedList<int> DataList, test;
int num;

cout << "Enter a list of positive integers ending with -999: " << endl;
cin >> num;
while(num != -999){
DataList.insert(num);
cin >> num;
}

cout << endl;


cout << "List in ascending order: ";
DataList.print();
cout << endl;

cout << "List in descending order: ";


DataList.reversePrint();
cout << endl;

cout << "Enter item to be deleted: ";


cin >> num;
cout << endl;

DataList.deleteNode(num);
cout << "List after deleting " << num << " : ";
DataList.print();
cout << endl;

cout << "Enter item to be searched: ";


cin >> num;
cout << endl;

if(DataList.search(num)){
cout << num << " found in the list." << endl;
}

else {
cout << num << " is not in the list." << endl;
}

cout << "********Testing copy constructor***********" << endl;

TCC(DataList);
cout << "intList: ";
DataList.print();
cout << endl;

test.destroy()

cout << "********Testing assignment operator***********" << endl;

test = DataList;
cout << "temp: ";
DataList.print();

cout << endl;

return 0;
}

_________________________________________________________________________________________________
CPE104L Data Structures and Algorithms
School of Electrical, Electronics, and Computer Engineering Page | 4
Laboratory Report 1
POINTERS, LINKED LISTS, AND STACKS
void TCC(doublyLinkedList<int> list)

3. Write a program that takes as input an arithmetic expression followed by a semicolon ;. The program
outputs whether the expression contains matching grouping symbols. For example, the arithmetic
expressions {25 + (3 – 6) * 8} and 7 + 8 * 2 contain matching grouping symbols. However, the expression 5 +
{(13 + 7) / 8 - 2 * 9 does not contain matching grouping symbols.

If the expression contains matching grouping symbols, the program output should contain the following text:
Expression has matching grouping symbol. If the expression does not contain matching grouping symbols,
the program output should contain the following text: Expression does not have matching grouping symbols.

Screenshot of Output

Screenshot of Codes

Source Code
#include <iostream>
#include "myStack.h"

using namespace std;

bool hasMatchingGroupingSymbols(const string& expression) {


stackType<char> symbolStack;

for (char symbol : expression) {

if (symbol == '(' || symbol == '{' || symbol == '[') {


symbolStack.push(symbol);
} else if (symbol == ')' || symbol == '}' || symbol == ']') {
if (symbolStack.isEmptyStack()) {
return false;
}

char openSymbol = symbolStack.top();


symbolStack.pop();
if ((symbol == ')' && openSymbol != '(') ||
(symbol == '}' && openSymbol != '{') ||
(symbol == ']' && openSymbol != '[')) {
return false;
}
}
}
return symbolStack.isEmptyStack();
}

int main() {
string expression;

getline(cin, expression, ';');

if (hasMatchingGroupingSymbols(expression)) {
cout << "Expression has matching grouping symbols" << endl;

}
else {
cout << "Expression does not have matching grouping symbols" << endl;
_________________________________________________________________________________________________
CPE104L Data Structures and Algorithms
School of Electrical, Electronics, and Computer Engineering Page | 5
Laboratory Report 1
POINTERS, LINKED LISTS, AND STACKS
}

return 0;

_________________________________________________________________________________________________
CPE104L Data Structures and Algorithms
School of Electrical, Electronics, and Computer Engineering Page | 6
Laboratory Report 1
POINTERS, LINKED LISTS, AND STACKS
C. Findings, Observations, and Comments:
Guiding Questions :
1. Did you solve the coding exercise/s?
2. Are there any difficulties during coding or set-up that you encountered?
3. What are your findings, observations, and comments in the coding exercise?

(Please type your findings, observations, and comments according to the guide questions in a paragraph
format.)
1. Unfortunately, during the lab, I didn’t finished the laboratory experiment but I tried to code it
when I got home.
2. I find it hard to code all the parts of the laboratory since I didn’t finished this part during the lab
and it took me hours to finished all the laboratory
3. Yes, even though it took me so long to finish the coding I learned a lot how to code about
pointers linked lists and stacks.

_________________________________________________________________________________________________
CPE104L Data Structures and Algorithms
School of Electrical, Electronics, and Computer Engineering Page | 7
Laboratory Report 1
POINTERS, LINKED LISTS, AND STACKS
D. Score Sheet

Poor Fair Good Excellent


Criteria Score
(25%) (50%) (75%) (100%)
The report was The report was The report was The report was
incomplete, complete, complete, neat, complete, neat,
I. Completeness,
messy, and had messy, and had and had 1 or 2 and all the
Documentation, and
many many unanswered questions had
Organization of Report
unanswered unanswered questions. been answered.
questions. questions.
The program The program The program The program
had had corrected had corrected had appropriate
inappropriate indention, but indention, elements and
elements and inappropriate adequate structures,
II. Coding Design and
structures, elements and program correct
Patterns
incorrect structures and documentation, indention, and
indention, and poor program but inappropriate excellent
poor program documentation. elements and program
documentation. structures. documentation.
The findings. The findings. The findings. The findings.
observations, observations, observations, observations,
and comments and comments and comments and comments
were not based based on the were based on were based on
on the gathered gathered data the gathered the gathered
III. Findings, Observations, data and results. and results but data and results data and results
and Comments All thoughts were not and were mostly and were
were elaborated. Not elaborated. Most completely
inconsistent and all thoughts were of the thoughts elaborated. All
unclear. consistent and were consistent the thoughts
clear. and clear. were consistent
and clear.
The words used The words used The words used The words used
were were were were
inappropriate, appropriate; appropriate, had appropriate, had
IV. Grammar and wrong grammar however, bad proper grammar proper grammar
Composition usage, and poor grammar and usage, but poor usage, and
sentence poor sentence sentence excellent
construction was construction construction was sentence
observed. were observed. observed. construction.

SCORE:

CHECKED
Signature
Rating
Date

_________________________________________________________________________________________________
CPE104L Data Structures and Algorithms
School of Electrical, Electronics, and Computer Engineering Page | 8

You might also like