Professional Documents
Culture Documents
Algorithm CC0007: College of Computer Studies
Algorithm CC0007: College of Computer Studies
Algorithm CC0007: College of Computer Studies
Algorithm
CC0007
Machine Problem # 2C
Submitted by:
Submitted to:
1
Table of Contents
Introduction............................................................................................................................3
Algorithm................................................................................................................................3
Screen Output and User’s manual...........................................................................................4
Test Cases...............................................................................................................................5
Source Code...........................................................................................................................6
Conclusion...............................................................................................................................6
References............................................................................................................................12
2
Introduction
This program implements Bubble Sort Algorithm, Functions, and File Handling on a
Doubly Linked List using C++. The program should be able to accept a number of inputted data,
and using those data, create a Doubly Linked list, display the unsorted list and then perform
Bubble Sort on the linked list, and then display again.
Algorithm
3
Screen Output and User’s manual
This is the part where the program asked for the limit and the integer data to be stored in the
linked list.
This displays the Address, Previous Address, data, and the Next Address details of each node.
This follows the sequence as the linked list was created, before Bubble Sort was performed.
4
Figure 3. Table of Bubble Sorted Linked List
This displays the Address, Previous Address, data, and the Next Address details of each node.
This follows the sequence after Bubble Sort was performed.
Test Cases
Positive Test
Test Case Test Test Steps Test Data Expected Actual Result Pass/Fail
ID Scenario Result
1 The user is 1. Run the Input data The user The program Pass
inputting application should see shows the
value to using the output values
the codio,
program (command Unsorted: Unsorted:
use) 239710 239710 239710
2. From the
menu BubbleSorted BubbleSorted
select : :
choice. 012379 012379
Negative Test
Test Case Test Test Steps Test Data Expected Actual Result Pass/Fail
ID Scenario Result
1 The user is 1. Run the Input The user The program Fail
inputting application should see shows the
value to using the output value
the codio,
program (command Unsorted: Unsorted:
use) 239710 239710 239710
2. From the
menu BubbleSorted BubbleSorted
select : :
choice. 012379 239710
5
Source Code
#include <iostream>
6
struct Node {
int data;
};
7
newNode->data = new_data;
//new node is the last node , so set next of new node to null
newNode->next = NULL;
//check if list is empty, if yes make new node the head of list
if (*head == NULL) {
newNode->prev = NULL;
*head = newNode;
return;
last = last->next;
last->next = newNode;
newNode->prev = last;
8
return;
int temp;
if(node == NULL) {
return;
else {
while(current != NULL) {
index = current->next;
while(index != NULL) {
//If current node's data is greater than index's node data, swap the data between
them
temp = current->data;
9
current->data = index->data;
index->data = temp;
index = index->next;
current = current->next;
// This function prints contents of linked list starting from the given node
while(temp!= NULL){
10
temp = temp-> next;
else{
//main program
int main() {
11
struct Node *head = NULL;
int size;
cout << "Enter " << size << " elements: ";
for (int i = 0; i < size; ++i) { // store input from user to array
for (int i = 0; i < size; ++i) { // store input from user to array
List(&head, num[i]);
displayList(head);
bubbleSort(head, size);
12
displayList(head);
return 0;
Conclusion
Doubly Linked List is one of the types of a linked list and for this program, the data
saved in each node was assigned with the use of a for loop and an array. This just means that
even though the double linked list is the main data structure that the program requires, making
use of other data structures and different types of loops can help implement the linked list.
Bubble Sort and other sorting algorithms also make use of combinations of different
programming concepts and techniques to produce more efficient and accurate programs.
References
GeeksForGeeks(www.geeksforgeeks.org)
W3schools(www.w3schools.com)
Tutorialspoint(www.tutorialspoint.com)
13