Tackling repetitive tasks with serial or parallel programming in RLun-Hsien Chang
R programming basics
● Syntax forms, data structure, vector, elapsed time
Serial computing
● For loop, vectorised functions, *apply() functions
Parallel computing
● The doParallel, parallel, foreach package
Compare time performance in serial and parallel computing
This presentations gives an introduction to the data structure linked-lists. I discuss the implementation of header-based linked-lists in C. The presentation runs through the code and provides the visualization of the code w.r.t pointers.
Following presentation gives the brief view about dynamic memory allocation used for allocating space at runtime.
Go through the slides hope it will be helpful to get the basic knowledge about the dynamic memory allocation.
Please comment and shares your views.
Tackling repetitive tasks with serial or parallel programming in RLun-Hsien Chang
R programming basics
● Syntax forms, data structure, vector, elapsed time
Serial computing
● For loop, vectorised functions, *apply() functions
Parallel computing
● The doParallel, parallel, foreach package
Compare time performance in serial and parallel computing
This presentations gives an introduction to the data structure linked-lists. I discuss the implementation of header-based linked-lists in C. The presentation runs through the code and provides the visualization of the code w.r.t pointers.
Following presentation gives the brief view about dynamic memory allocation used for allocating space at runtime.
Go through the slides hope it will be helpful to get the basic knowledge about the dynamic memory allocation.
Please comment and shares your views.
linked list
singly linked list
insertion in singly linked list
DELETION IN SINGLY LINKED LIST
Searching a singly linked list
Doubly Linked List
insertion from Doubly linked list
DELETION from Doubly LINKED LIST
Searching a doubly linked list
Circular linked list
With the rapid growth of the production and storage of large scale data sets it is important to investigate methods to drive the cost of storage systems down. We are currently in the midst of an information explosion and large scale storage centers are increasingly used to help store generated data. There are several methods to bring the cost of large scale storage centers down and we investigate a technique that focuses on transitioning storage disks into lower power states. This talk introduces a model of disk systems that leverages disk access patterns to produce energy saving opportunities for parallel disk systems. We also focus on the implementation of an energy-efficient storage cluster, where a couple of energy-saving techniques are incorporated. Our modeling and simulation results indicated that large data sizes and knowledge about the disk access pattern are valuable for storage system energy savings techniques. Storage servers that support applications that stream media is one key area that would benefit from our strategies.
linked list
singly linked list
insertion in singly linked list
DELETION IN SINGLY LINKED LIST
Searching a singly linked list
Doubly Linked List
insertion from Doubly linked list
DELETION from Doubly LINKED LIST
Searching a doubly linked list
Circular linked list
With the rapid growth of the production and storage of large scale data sets it is important to investigate methods to drive the cost of storage systems down. We are currently in the midst of an information explosion and large scale storage centers are increasingly used to help store generated data. There are several methods to bring the cost of large scale storage centers down and we investigate a technique that focuses on transitioning storage disks into lower power states. This talk introduces a model of disk systems that leverages disk access patterns to produce energy saving opportunities for parallel disk systems. We also focus on the implementation of an energy-efficient storage cluster, where a couple of energy-saving techniques are incorporated. Our modeling and simulation results indicated that large data sizes and knowledge about the disk access pattern are valuable for storage system energy savings techniques. Storage servers that support applications that stream media is one key area that would benefit from our strategies.
An Active and Hybrid Storage System for Data-intensive ApplicationsXiao Qin
Since large-scale and data-intensive applications have been widely deployed, there is a growing demand for high-performance storage systems to support data-intensive applications. Compared with traditional storage systems, next-generation systems will embrace dedicated processor to reduce computational load of host machines and will have hybrid combinations of different storage devices. We present a new architecture of active storage system, which leverage the computational power of the dedicated processor, and show how it utilizes the multi-core processor and offloads the computation from the host machine. We then solve the challenge of applying the active storage node to cooperate with the other nodes in the cluster environment by design a pipeline-parallel processing pattern and report the effectiveness of the mechanism. In order to evaluate the design, an open-source bioinformatics application is extended based on the pipeline-parallel mechanism. We also explore the hybrid configuration of storage devices within the active storage. The advent of flash-memory-based solid state disk has become a critical role in revolutionizing the storage world. However, instead of simply replacing the traditional magnetic hard disk with the solid state disk, researchers believe that finding a complementary approach to corporate both of them is more challenging and attractive. Thus, we propose a hybrid combination of different types of disk drives for our active storage system. An simulator is designed and implemented to verify the new configuration. In summary, this dissertation explores the idea of active storage, an emerging new storage configuration, in terms of the architecture and design, the parallel processing capability, the cooperation of other machines in cluster computing environment, and the new disk configuration, the hybrid combination of different types of disk drives.
Reliability Analysis for an Energy-Aware RAID SystemXiao Qin
Reliability Analysis for an Energy-Aware RAID System.
S. Yin, M. I. Alghamdi, X.-J. Ruan, Y. Tian, J. Xie, X. Qin, and M. Qiu, Proc. the 30th IEEE International Performance Computing and Communications Conference (IPCCC), Nov. 2011.
Project 2 in COMP3500 Operating Systems class at Auburn University. The objectives of this project are:
• Use your installed CentOS to build OS/161 and run Sys/161
• Configure and build OS/161 kernels
• Discover important design aspects of OS/161 by examining its source code
• Manage OS/161 using a version control system called cvs; apply cvs to create a repository and tracking your source code changes
• Use GDB to debug OS/161
I rebuilt the kernel by adding "hello world!" into the boot message. In what follows, I summarize my process of rebuilding the OS161 kernel. You may also found the three common mistakes at the end of this document.
Conference Program Overview of the
31st IEEE International Performance Computing and Communications Conference (IPCCC'12). December 1st - December 3rd, 2012
IPCCC 2012 - Austin, Texas, USA
This module shows you how to install a software development framework for OS/161.
Lecture: 30 minutes – Slides 1-20.
Demo: 20 minutes
1. Project 2 Specification.docx Preview the documentView in a new window 2. How to build tool chain: The MIPS toolchain for os161.txtPreview the documentView in a new window 3. How to build and run sys161.htmlView in a new window 4. gdb.htm View in a new window and cvs.htmView in a new window 5. Configuration file: sys161.confView in a new window Below, you can find five source code packages: 6. os161-1.10.tar.gzView in a new window 7. cs161-binutils-1.4.tarView in a new window 8. Download cs161-gcc-1.4.tar from: https://dl.dropboxusercontent.com/u/24238235/cs161-gcc-1.4.tar 9. Download cs161-gdb-1.4.tar from: https://dl.dropboxusercontent.com/u/24238235/cs161-gdb-1.4.tar 10. sys161-1.12.tar.gzView in a new window
Thermal modeling and management of cluster storage systems xunfei jiang 2014Xiao Qin
Thermal Modeling and Management of Storage Systems
Author: Jiang, Xunfei
Abstract: Energy consumption of data storage systems has increased significantly for the past decades. There is an urgent need to build energy-efficient data storage systems. Computing cost of IT facilities and cooling cost of air conditioners contribute to a large portion of the total energy consumption of data centers. A large amount of researchers focus on reducing the computing cost by balancing workload or powering off idle data nodes to save energy. In recent years, growing attention has been paid to decreasing the cooling cost. Temperature is a major contributor to cooling cost, and thermal management has become a popular topic in building energy-efficient data centers. Extensive research of thermal impacts of processors and memories has been presented in literature, however, the thermal impacts of disks have not been fully investigated. In this dissertation, experiments are conducted to characterize the thermal behavior of processors and disks by using real-world benchmarks (e.g., postmark and whetstone). The profiling results show that disks have comparable thermal impacts as processors to overall temperature of a data node. Then, we develop an approach to generate thermal models for estimating temperatures of processors, disks, and data nodes. We validate the thermal models by comparing the predictions with real measurements by temperature sensors deployed on data nodes. We further propose an energy model to estimate the total energy cost of data nodes. Finally, by applying our thermal and energy models, we propose thermal management strategies for building energy-efficient data centers. These strategies include a thermal-aware task scheduling strategy, thermal-aware data placement strategies for homogeneous and hybrid storage clusters, and a predictive thermal-aware data transmission strategy.
Why Major in Computer Science and Software Engineering at Auburn University?Xiao Qin
Computer scientists and software engineers design, analyze, and develop software for the computer systems and networks that power today's world. Whether you're playing a video game, downloading MP3s, talking on a cell phone or even driving your car, you're depending on software. Software applications range from personal computing to entertainment systems to life-critical applications such as medical, flight and space systems. Today's society requires software that is engineered to demanding performance, reliability and safety standards. Engineering such software requires a high degree of specialization. The individuals with the critical expertise to do this are computer scientists and software engineers. It's these professionals who make the magic happen.
The Department of Computer Science and Software Engineering (CSSE) offers three undergraduate degrees to prepare students for success in the world of computing:
Bachelor of Science in Computer Science
Bachelor of Software Engineering
Bachelor of Wireless Engineering
Note: I rebuilt the kernel by adding "hello world!" into the boot message. In what follows, I summarize my process of rebuilding the OS161 kernel. You may also found the three common mistakes at the end of this document.
Project 2 how to install and compile os161Xiao Qin
README: After installed VirtualBox on my Windows machine, I installed CentOS 6.5 on VirtualBox. Next, I successfully installed cs161-binutils-1.4 and cs161-gcc-1.5.tar. Unfortunately, I encountered an error "configure: error: no termcap library found". As Dustin suggested, installing the missing package can solve this problem. Please use the following command to install the package:
yum install ncurses-devel
You don't have to install CentOS 6.5, because I believe that you can install all the OS161 tools on CentOS 7. You don't have to install VirtualBox neither. Nevertheless, if you decide to install CentOS on VirtualBox, please refer to my installation log below.
How to survive a group project in COMP4710 Senior Design Project? This is a training module in the second lecture of week 1. The module takes approximately 20 minutes. After the training session is done, please check the progress of the development groups.
Data center specific thermal and energy saving techniquesXiao Qin
Abstract: Data centers are ever increasing as we become more reliant of web based transactions. The benefits of such massive computing are obvious by the speed and ease we can get most media or information. A challenge is that new large data centers introduce a level of energy consumption that the world has not seen before. The obvious energy cost of running the computers is a billion dollar problem, but there are hidden costs like running cooling systems as well. To help combat the problems of large data centers, we aim at developing solutions that can work for each type of data center. This could entail creating tools that are generic enough to work for all data centers, or focusing on specific tools the type of software running in the data center. In this talk, we present a thermal model that is flexible enough to be applicable for all data centers; we show how our model can be used to save energy. We also discuss new energy saving techniques for Hadoop clusters specifically, where we focus on very data centric implementations of Hadoop to gain a significant energy savings.
Understanding what our customer wants-slideshareXiao Qin
COMP4710 Senior Design Project - Training Module 2. How to understand our customers' requirements? This training module is covered in the second lecture of week 2 or Lec02b.
This assignment and the next (#5) involve design and development of a.pdfEricvtJFraserr
This assignment and the next (#5) involve design and development of a sequential
non contiguous and dynamic datastructure called LinkedList. A linked list object is
a container consisting of connected ListNode objects. As before, we are not going
to use pre-fabricated classes from the c++ library, but construct the LinkedList
ADT from scratch.
The first step is construction and testing of the ListNode class. A ListNode object
contains a data field and a pointer to the next ListNode object (note the recursive
definition).
#This assignment requires you to
1. Read the Assignment 4 Notes
2. Watch the Assignment 4 Support video
3. Implement the following methods of the ListNode class
-custom constructor
-setters for next pointer and data
4. Implement the insert and remove method in the main program
5. Scan the given template to find the above //TODO and implement the code
needed
//TODO in ListNodecpp.h file
public: ListNode(T idata, ListNode<T> * newNext);
public: void setNext(ListNode<T> * newNext);
public: void setData(T newData);
// TODO in main program
void remove(ListNode<int> * &front,int value)
void insert(ListNode<int> * &front,int value)
# The driver is given ListNodeMain.cpp is given to you that does the following
tests
1. Declares a pointer called front to point to a ListNode of datatype integer
2. Constructs four ListNodes with data 1,2,4 and adds them to form a linked
list.
3. Inserts ListNode with data 3 to the list
4. Removes node 1 and adds it back to test removing and adding the first
element
5. Removes node 3 to test removing a middle node
6. Removes node 4 to test removing the last node
7. Attempt to remove a non existent node
8. Remove all existing nodes to empty the list
9. Insert node 4 and then node 1 to test if insertions preserve order
10.Print the list
Main.cpp
#include <iostream>
#include "ListNodecpp.h"
// REMEMBER each ListNode has two parts : a data field
// and an address field. The address is either null or points to the next node
//in the chain
//Requires: integer value for searching, address of front
//Effects: traverses the list node chain starting from front until the end comparing search value
with listnode getData. Returns the original search value if found, if not adds +1 to indicate not
found
//Modifies: Nothing
int search(ListNode<int> * front, int value);
//Requires: integer value for inserting, address of front
//Effects: creates a new ListNode with value and inserts in proper position (increasing order)in
the chain. If chain is empty, adds to the beginning
//Modifies: front, if node is added at the beginning.
//Also changes the next pointer of the previous node to point to the
//newly inserted list node. the next pointer of the newly inserted pointer
//points to what was the next of the previous node.
//This way both previous and current links are adjusted
//******** NOTE the use of & in passing pointer to front as parameter -
// Why do you think this is needed ?**********
void insert(ListNode<int> * &fr.
Write a program that accepts an arithmetic expression of unsigned in.pdfJUSTSTYLISH3B2MOHALI
Write a program that accepts an arithmetic expression of unsigned integers in postfix notation
and builds the arithmetic expression tree that represents that expression. From that tree, the
corresponding fully parenthesized infix expression should be displayed and a file should be
generated that contains the three address format instructions. This topic is discussed in the week
4 reading in module 2, section II-B. The main class should create the GUI shown below:
Pressing the Construct Tree button should cause the tree to be constructed and using that tree, the
corresponding infix expression should be displayed and the three address instruction file should
be generated. The postfix expression input should not be required to have spaces between every
token. Note in the above example that 9+- are not separated by spaces. The above example
should produce the following output file containing the three address instructions:
Add R0 5 9
Sub R1 3
R0 Mul R2 2 3
Div R3 R1 R2
Inheritance should be used to define the arithmetic expression tree. At a minimum, it should
involve three classes: an abstract class for the tree nodes and two derived classes, one for
operand nodes and another for operator nodes. Other classes should be included as needed to
accomplish good object-oriented design. All instance data must be declared as private.
You may assume that the expression is syntactically correct with regard to the order of operators
and operands, but you should check for invalid tokens, such as characters that are not valid
operators or operands such as 2a, which are not valid integers. If an invalid token is detected a
RuntimeException should be thrown and caught by the main class and an appropriate error
message should be displayed. Three Adddress Generator Enter Postfix Expression 359 2 3
Construct Tree Infix Expression ((3-(5 9))/ (2* 3
Solution
#include
#include
#include
#include
#include
struct TREE //Structure to represent a tree
{
char data;
struct TREE *right,*left,*root;
};
typedef TREE tree; /* Stack Using Linked List */
struct Stack //Structure to represent Stack
{
struct TREE *data;
struct Stack *next,*head,*top; //Pointers to next node,head and top
};
typedef struct Stack node;
node *Nw; //Global Variable to represent node
void initialize(node *&n)
{
n = new node;
n -> next = n -> head = n -> top = NULL;
}
void create(node *n)
{
Nw = new node; //Create a new node
Nw -> next = NULL; //Initialize next pointer field
if(n -> head == NULL) //if first node
{
n -> head = Nw; //Initialize head
n -> top = Nw; //Update top
}
}
void push(node *n,tree *ITEM)
{
node *temp = n -> head;
if(n -> head == NULL) //if First Item is Pushed to Stack
{
create(n); //Create a Node
n -> head -> data = ITEM; //Insert Item to head of List
n -> head = Nw;
return; //Exit from Function
}
create(n); //Create a new Node
Nw -> data = ITEM; //Insert Item
while(temp -> next != NULL)
temp = temp -> next; //Go to Last Node
temp -> next = Nw; //Point New node
n -> top = Nw; //Upda.
How do you stop infinite loop Because I believe that it is making a.pdffeelinggift
How do you stop infinite loop? Because I believe that it is making an infinite circular list.
c++ code:
Here is the list class:
#ifndef LIN_J_LIST
#define LIN_J_LIST
typedef unsigned int uint;
#include
#include
using namespace std;
/**
* a simplified generic singly linked list class to illustrate C++ concepts
* @author Jerry Lin
* @version 2/17/17
*/
template< typename Object >
class List
{
private:
/**
* A class to store data and provide a link to the next node in the list
*/
class Node
{
public:
/**
* The constructor
* @param data the data to be stored in this node
*/
explicit Node( const Object & data )
: data{ data }, next{ nullptr } {}
Object data;
Node * next;
};
public:
/**
* The constructor for an empty list
*/
List()
: size{ 0 }, first{ nullptr }, last{ nullptr } {}
/**
* the copy constructor-creates and copy the list
*/
List( List && rhs ) = delete;
List( const List & rhs )
{
count = 0;
size = 0;
if(rhs.size != 0)
{
push_front(rhs.front());
Node * current = rhs.first;
Node * tempNode = first;
size++;
while(current->next != nullptr)
{
current = current->next;
Node *newNode = new Node(current->data); //transfer the data. basic op.
count++;
tempNode->next = newNode;
last = newNode;
tempNode = tempNode->next;
size++;
}
}
// you document and implement this method
}
/**
* the operator= method-copies the list
*/
List & operator=( List && rhs) = delete;
List & operator=( const List & rhs )
{
count = 0;
size = 0;
if( size != 0 )
{
Node * current = first;
Node * temp;
while( current != nullptr )
{
temp = current;
current = current->next;
delete temp;
}
}
if(rhs.size!= 0)
{
push_front(rhs.front());
Node * current = rhs.first;
Node * tempNode = first; //create a temporary to store
size++;
while(current -> next != nullptr)
{
current = current->next;
Node *newNode = new Node(current->data); //transfer the data. basic op
count++;
tempNode->next = newNode;
last = newNode;
tempNode = tempNode -> next;
size++;
}
}
return *this;
// you document and implement this method
}
/**
* accessor
* @return count
*/
int get_count() const
{
return count;
}
/**
* The destructor that gets rid of everything that\'s in the list and
* resets it to empty. If the list is already empty, do nothing.
*/
~List()
{
if( size != 0 )
{
Node * current = first;
Node * temp;
while( current != nullptr )
{
temp = current;
current = current->next;
delete temp;
}
}
}
/**
* Put a new element onto the beginning of the list
* @param item the data the new element will contain
*/
void push_front( const Object& item )
{
Node * new_node = new Node( item );//basic op.
if(is_empty())
{
last = new_node;
}
else
{
new_node->next = first;
}
first = new_node;
size++;
/* you complete the rest */
}
/**
* Remove the element that\'s at the front of the list. Causes an
* assertion error if the list is empty.
*/
void pop_front()
{
assert( !is_empty() );
Node * temp = first;
if( first == last )
{
first = last = nullptr;
}
else
{
first = first->next;
}
delete temp;
size--;
}
/**
* Accessor to return the da.
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED .pdffathimahardwareelect
THE CODE HAS A SEGMENTATION FAULT BUT I CANNOT FIND OUT WHERE. NEED
HELP FIXING THIS CODE?
THIS IS THE PROBLEM
Write a program that allows the user to enter two positive integers and outputs their sum. Sounds
simple? Here\'s the catch: The numbers may be any size! They may be way too large to store in a
single variable. You may not assume any particular maximum number of digits.
HERE IS THE CODE
#include
#include
struct node /* Linked list node*/
{
int data;
struct node* next;
};
struct node *newNode(int data) /* Function to create a new node with giving the data*/
{
struct node *new_node = (struct node *) malloc(sizeof(struct node));
new_node->data = data;
new_node->next = NULL;
return new_node;
}
void push(struct node** head_ref, int new_data) /* Function to insert a node at the beginning of
the Doubly Linked List*/
{
struct node* new_node = newNode(new_data); /*allocate a node*/
new_node->next = (*head_ref); /* link the old list off to the new node*/
(*head_ref) = new_node; /*move the head to point to the new node*/
}
/* Adding the contents of two linked lists and return the head node of resultant list*/
struct node* addTwoLists (struct node* first, struct node* second)
{
struct node* res = NULL; /* res is head node of the resultant list*/
struct node *temp, *prev = NULL;
int carry = 0, sum;
while (first != NULL || second != NULL) /*while both the lists exists*/
{
/* Calculate value of next digit in resultant list.
// The next digit is sum of following things
// (i) Carry
// (ii) Next digit of first list (if there is a next digit)
// (ii) Next digit of second list (if there is a next digit)*/
sum = carry + (first? first->data: 0) + (second? second->data: 0);
carry = (sum >= 10)? 1 : 0; /* update carry for next calulation*/
sum = sum % 10; /*update sum if it is greater than 10*/
temp = newNode(sum); /*Create a new node with sum as data*/
if(res == NULL) /*if this is the first node then set it as head of the resultant list*/
res = temp;
else /* If this is not the first node then connect it to the rest.*/
prev->next = temp;
prev = temp; /* Set prev for next insertion*/
if (first) first = first->next; /* Move first pointers to next node*/
if (second) second = second->next; /*Move second pointer to the next node*/
}
if (carry > 0)
temp->next = newNode(carry);
return res; /* return head of the resultant list*/
}
void printList(struct node *node) /* function to print a linked list*/
{
while(node != NULL)
{
printf(\"%d \", node->data);
node = node->next;
}
printf(\"\ \");
}
int main(void) /* program to test above function*/
{
struct node* res = NULL;
struct node* first = NULL;
struct node* second = NULL;
printf(\"Enter first positive integer: \");
scanf(\"%d\",&first);
printList(first);
printf(\"Enter second positive integer: \");
scanf(\"%d\",&second);
printList(second);
/*Add the two lists and see result*/
res = addTwoLists(first, second);
printf(\"Sum is: %d\");
printList(res);
return 0;
}
Solution
#include
#include
typedef struct Node
{
int da.
Data Structures in C++I am really new to C++, so links are really .pdfrohit219406
Data Structures in C++
I am really new to C++, so links are really hard topic for me. It would be nice if you can provide
explanations of what doubly linked lists are and of some of you steps... Thank you
In this assignment, you will implement a doubly-linked list class, together with some list
operations. To make things easier, you’ll implement a list of int, rather than a template class.
Solution
A variable helps us to identify the data. For ex: int a = 5; Here 5 is identified through variable a.
Now, if we have collection of integers, we need some representation to identify them. We call it
array. For ex: int arr[5]
This array is nothing but a Data Structure.
So, a Data Structure is a way to group the data.
There are many Data Structures available like Arrays, Linked List, Doubly-Linked list, Stack,
Queue, etc.
Doubly-Linked list are the ones where you can traverse from the current node both in left and
right directions.
Why so many different types of Data Structures are required ?
Answer is very simple, grouping of data, storage of data and accessing the data is different.
For example, in case of Arrays we store all the data in contiguous locations.
What if we are not able to store the data in contiguous locations because we have huge data.
Answer is go for Linked List/Doubly-Linked list.
Here we can store the data anywhere and link the data through pointers.
I will try to provide comments for the code you have given. May be this can help you.
#pragma once
/*
dlist.h
Doubly-linked lists of ints
*/
#include
class dlist {
public:
dlist() { }
// Here we are creating a NODE, it has a integer value and two pointers.
// One pointer is to move to next node and other to go back to previous node.
struct node {
int value;
node* next;
node* prev;
};
// To return head pointer, i.e. start of the Doubly-Linked list.
node* head() const { return _head; }
// To return Tail pointer, i.e. end of the Doubly-Linked list.
node* tail() const { return _tail; }
// **** Implement ALL the following methods ****
// Returns the node at a particular index (0 is the head).
node* at(int index){
int cnt = 0;
struct node* tmp = head();
while(tmp!=NULL)
{
if (cnt+1 == index)
return tmp;
tmp = tmp->next;
}
}
// Insert a new value, after an existing one
void insert(node *previous, int value){
// check if the given previous is NULL
if (previous == NULL)
{
printf(\"the given previous node cannot be NULL\");
return;
}
// allocate new node
struct node* new_node =(struct node*) malloc(sizeof(struct node));
// put in the data
new_node->data = new_data;
// Make next of new node as next of previous
new_node->next = previous->next;
// Make the next of previous as new_node
previous->next = new_node;
// Make previous as previous of new_node
new_node->prev = previous;
// Change previous of new_node\'s next node
if (new_node->next != NULL)
new_node->next->prev = new_node;
}
// Delete the given node
void del(node* which){
struct node* head_ref = head();
/* base case */
if(*head_ref == NUL.
I am Gabriel C. I am a C Exam Expert at programmingexamhelp.com. I hold a PhD. in Business analyst of Information Technology, Montreal College of Information Technology, Canada. I have been helping students with their exams for the past 8 years. You can hire me to take your exam in C.
Visit programmingexamhelp.com or email support@programmingexamhelp.com. You can also call on +1 678 648 4277 for any assistance with the C Exam.
In C++Write a recursive function to determine whether or not a Lin.pdfflashfashioncasualwe
In C++
Write a recursive function to determine whether or not a Linked List is in sorted order (smallest
value to largest value).
Add the following function prototypes to your List class under the section for access functions,
then implement the functions below the class definition:
public:
/**Access Functions*/
bool isSorted();
//Wrapper function that calls the isSorted helper function to determine whether
//a list is sorted in ascending order.
//We will consider that a list is trivially sorted if it is empty.
//Therefore, no precondition is needed for this function
private:
bool isSorted(Nodeptr node);
//Helper function for the public isSorted() function.
//Recursively determines whether a list is sorted in ascending order.
#include //for NULL
#include
#include
using namespace std;
template //list stores generic list data, not any specific C++ type
class List
{
private:
struct Node
{
listdata data;
Node* next;
Node* previous;
Node(listdata data): data(data), next(NULL), previous(NULL){}
};
typedef struct Node* Nodeptr;
Nodeptr first;
Nodeptr last;
Nodeptr iterator;
int size;
public:
/**Constructors and Destructors*/
List();
//Default constructor; initializes and empty list
//Postcondition: numeric values equated to zero, or strings should be empty.
List(const List &list);
~List();
//Destructor. Frees memory allocated to the list
//Postcondition: position NodePtr at next Node
/**Accessors*/
listdata getFirst();
//Returns the first element in the list
//Precondition:NodePtr points to the first node on list
listdata getLast();
//Returns the last element in the list
//Precondition: make new node first on the list
listdata getIterator();
bool isEmpty();
//Determines whether a list is empty.
int getSize();
//Returns the size of the list
/**Manipulation Procedures*/
void startIterator();
void advanceIterator();
void removeLast();
//Removes the value of the last element in the list
//Precondition: list is not empty, not the first element.
//Postcondition: one remaining node
void removeIterator();
void removeFirst();
//Removes the value of the first element in the list
//Precondition: list is not empty
//Postcondition: no nodes left
void insertLast(listdata data);
//Inserts a new element at the end of the list
//If the list is empty, the new element becomes both first and last
//Postcondition: next equal to null
void insertFirst(listdata data);
//Inserts a new element at the start of the list
//If the list is empty, the new element becomes both first and last
//Postcondition:point nodePtr next node on list
/**Additional List Operations*/
bool offEnd();
void printList();
//Prints to the console the value of each element in the list sequentially
//and separated by a blank space
//Prints nothing if the list is empty
void insertIterator(listdata data);
bool operator==(const List &list);
};
// constructor definition
template
List::List(): first(NULL), last(NULL), iterator(NULL), size(0) {}
template
List::List(const List &list): size(list.size)
{
if(list..
Use C++class Node{public Node ( int = 0 ); constru.pdfoptokunal1
Use C++
class Node{
public:
Node ( int = 0 ); // constructor with default value for
// info field
int info; // data
Node * next; // pointer to next node in the list
};
and put the constructor in Node.cpp
// Constructor
Node::Node ( int data )
{
info = data;
next = nullptr;
}
Write the following using the Node class.
A function that copies a linked list pointed to by ptr and returns a pointer to the copied list.
Please note: the copied list should be independent of the original list; the original list can be
destroyed and the copy should still remain.
const Node * copy (Node * ptr);
Solution
Need to perform \'Deep copy\' here :
const Node * copy (Node * ptr)
{
//Create new list to hold copied items
Node* newNode = new Node;
//Return if empty list
if (ptr->next == 0)
{
return newNode;
}
while(ptr !=NULL)
{
newNode->info = ptr->info;
newNode->next = ptr->next;
ptr = ptr ->next;
}
return newNode;
}.
I am Andrew O. I am a C Homework Expert at programminghomeworkhelp.com. I hold a master’s in Programming from, the University of Southampton, UK. I have been helping students with their homework for the past 10 years. I solve homework related to C.
Visit programminghomeworkhelp.com or email support@programminghomeworkhelp.com.
You can also call on +1 678 648 4277 for any assistance with C Homework.
Template LinkedList;I am using templates to make some linkedLists.pdffatoryoutlets
Sargent Corporation bought equipment on January 1, 2013. The equipment cost $180,000 and
had an expected salvage value of $30,000. The life of the equipment was estimated to be 6 years.
The book value of the equipment at the beginning of the third year using straight-line
depreciation would be . C $180,000. $150,000. $130,000. $50,000.
Solution
As per the information provided, Sargent Corporation bought an equipment on Jan 1, 2013 for
$180000 with 6 years life and salvage value of $30000.
Therefore, depreciation expense every year as per Straight line method would be:-
Equipment cost = $180000
LESS:- Salvage value = $30000
Amount on which depriciation is to be charged =$150000
Now, depreciation as per straight line method = $150000 / 6 years
= $25000 every year
Now, book value of Equipment at the beginning of third year is:-
Equipment cost = $180000
LESS :- Depreciation for first and second year = $25000 x 2 years = $50000
Therefore, book value at begginning of third year =$130000
Hence, as per the problem \"Option C\" is correct with book value of $130000..
Similar to COMP2710: Software Construction - Linked list exercises (20)
In this workshop, we explore ways to prepare for internship applications and interviews. In the workshop you will:
Learn how to apply for internships
Prepare for interview questions
Follow-up with employers
Receive tips that help you secure internships
An earlier version 1.0 can be found here: https://www.slideshare.net/xqin74/how-to-write-papers-part-1-principles/edit?src=slideview
5 Simple Steps to Write a Good Research Paper Title
1. Ask yourself these questions and make note of the answers What is my paper about? What techniques/ designs were used? Who/what is studied? What were the results?
2. Use your answers to list key words.
3. Create a sentence that includes the key words you listed.
4. Delete all unnecessary/repetitive words and link the remaining.
5. Delete non-essential information and reword the title.
Making a competitive nsf career proposal: Part 2 WorksheetXiao Qin
Dear Colleagues,
I created a worksheet to assist you to contrive the framework of your CAREER proposal. Answering the questions in the worksheet may streamline your thoughts when you are about to develop key components for your proposal. Any feedback on this worksheet is highly appreciated. I will have this worksheet revised in the future by incorporating your comments and suggestions.
Xiao (xqin@auburn.edu)
Making a competitive nsf career proposal: Part 1 TipsXiao Qin
A Caveat: This document consists of a list of the evaluation criteria of winning CAREER proposals. The following essential tips illustrate "what tasks" you should undertake rather than "how" to perform these tasks.
About This Document
" Proposal preparation phase: Sections 1 (Foundations), 2 (Preliminaries), and 6 (Other Suggestions) offer a list of tips on how to prepare your proposals.
" Proposal writing phase: Sections 3 (Key Components) and 4 (Writing) are comprised of a list of proposal components and writing styles.
" Proposal proofreading phase: Section 5 (Polishing a Proposal Draft) is a final proposal checklist.
In this training session, we provide new CSSE faculty with introduction on (1) policies related to graduate programs, (2) requirements and regulations, (3) teaching strategies, and (4) how to balance research and teaching. Please note that other CSSE policies (e.g., proposal submissions, startup account, CSSE committees) aren't covered in this session.
Subject: Welcome Letter
Dear New CSSE Graduate Students,
Welcome to the Department of Computer Science and Software Engineering at Auburn University. The CSSE faculty and I are enthusiastic about teaching and conducting cutting-edge research here; we are excited that you have chosen to join our department to pursue your Master’s or Ph.D. degrees. I am pleased to invite you to an orientation meeting on Thursday, Aug. 24 at 5:00 p.m. in room 3129 Shelby Center. At this kickoff meeting, I will present information on departmental policies, graduate school policies, CSSE graduate programs, assessments, academic standings, qualifying exams, teaching assistantship assignments, mailing list, job applications, E-mail etiquette and a whole lot more.
I look forward to seeing you all on Aug. 24.
Sincerely yours,
X. Qin
--
Xiao Qin, PhD
Professor and Director of Graduate Programs
Department of Computer Science and Software Engineering
3101 Shelby Center
Auburn University AL 36849-5347
voice: (334)844-6335
fax: (334)844-6329
WWW: http://www.eng.auburn.edu/~xqin
Watch this video at: https://www.youtube.com/watch?v=3u4AAGo31a8
Recorded on March 14, 2015. After having followed the Alfred’s adult piano course books for three years, I made a radical decision to learn a popular worship song called “Stream of Praise” [1]. A decade ago, I first learned how to sing this song when I was an assistant professor at New Mexico Tech, where minister Anna Tai [4] shared a Stream of Praise CD with me. I have listened this CD more than a few hundred times. The music video of this spiritual and emotional song can be found here https://www.youtube.com/watch?v=KIt9n2Wjlf8 [1] on YouTube.
It is worth mentioning that this song is a simple piano version of “Stream of Praise”. An advanced version of the song can be found here https://www.youtube.com/watch?v=DAOrSvexSJ8 [3]. It must take me at least 50 hours to learn this advanced version.
This video is a pilot project for me, because “Stream of Praise” is the first song I learned outside the Alfred’s-piano-book world. When I stayed away from Alfred’s piano books, I faced three grand challenges. First, it is non-trivial to choose a song that meets my current skill level. Second, there is no fingering suggestion marked on the sheet music. Last, no sample video found on YouTube. I tried various finger positions before finalizing my own style, which is marked on the sheet music posted in this video.
I am grateful to my colleague – Dr. Jeffrey Overbey [2] – for teaching me the correct finger positions of bars 4-5. I was amazed by Dr. Overbey’s sight reading skill; he read the sheet music for two seconds and immediately played the song. It took me over 19 hours to learn and practice; in contrast, he could play this song by sight-reading on the first attempt.
I would like to express my gratitude to Mike eKim (https://www.youtube.com/user/mbut123) [5], who offered insightful advice on how to play the first five measures. Mike demonstrated how to play these bars in a video (https://www.youtube.com/watch?v=_QeTQFviE88) posted on his YouTube channel [6].
I would like to thank Sean Fox for his advice on the fingering and tempo issues. He pointed out that I should play the sixteenth notes in bars 4-5 faster.
Bars 1-5 are very difficult; I could not make them musically sound until a practice of two hours. Fortunately, Mike's magic fingering position solved this problem (see [6] for the solution). Currently, I am learning how to play and sing at the same time. Ying enjoys singing this song when I play it on our piano.
The recording success rate is 19.2%, which is slightly higher than that (i.e., 12.5%) of the previous song. The tempo of this song is 83 BPM, which is marginally faster than the ideal one (i.e., 80 BPM).
A Summary of the Learning Process:
Tempo: 83 BPM (Ideal tempo: 80 BPM)
Recording: 47 minutes (26 takes, 5 acceptable videos)
Success Rate: 5/26 = 19.2%
HDFS-HC2: Analysis of Data Placement Strategy based on Computing Power of Nod...Xiao Qin
Hadoop and the term 'Big Data' go hand in hand. The information explosion caused
due to cloud and distributed computing lead to the curiosity to process and analyze massive
amount of data. The process and analysis helps to add value to an organization or derive
valuable information.
The current Hadoop implementation assumes that computing nodes in a cluster are
homogeneous in nature. Hadoop relies on its capability to take computation to the nodes
rather than migrating the data around the nodes which might cause a signicant network
overhead. This strategy has its potential benets on homogeneous environment but it might
not be suitable on an heterogeneous environment. The time taken to process the data on a
slower node on a heterogeneous environment might be signicantly higher than the sum of
network overhead and processing time on a faster node. Hence, it is necessary to study the
data placement policy where we can distribute the data based on the processing power of
a node. The project explores this data placement policy and notes the ramications of this
strategy based on running few benchmark applications.
Performance Evaluation of Traditional Caching Policies on a Large System with...Xiao Qin
Caching is widely known to be an effective method for improving I/O performance by storing frequently used data on higher speed storage components. However, most existing studies that focus on caching performance evaluate fairly small files populating a relatively small cache. Few reports are available that detail the performance of traditional cache replacement policies on extremely large caches. Do such traditional caching
policies still work effectively when applied to systems with petabytes of data? In this paper, we comprehensively evaluate
the performance of several cache policies, which include First-In-First-Out (FIFO), Least Recently Used (LRU) and Least
Frequently Used (LFU), on the global satellite imagery distribution application maintained by the U.S. Geological Survey
(USGS) Earth Resources Observation and Science Center (EROS). Evidence is presented suggesting traditional caching
policies are capable of providing performance gains when applied
to large data sets as with smaller data sets. Our evaluation is based on approximately three million real-world satellite images
download requests representing global user download behavior since October 2008.
Reliability Modeling and Analysis of Energy-Efficient Storage SystemsXiao Qin
With the rapid growth of the production and storage of large scale data sets it is important to investigate methods to drive the cost of storage systems down. Many
energy conservation techniques have been proposed to achieve high energy efficiency
in disk systems. Unfortunately, growing evidence shows that energy-saving schemes in disk drives usually have negative impacts on storage systems. Existing reliability models are inadequate to estimate reliability of parallel disk systems equipped with energy conservation techniques. To solve this problem, we firstly propose a mathematical model - called MINT - to evaluate the reliability of a parallel disk system where energy-saving mechanisms are implemented. In this dissertation, MINT is focused on modeling the reliability impacts of two well-known energy-saving techniques - the Popular Disk Concentration technique (PDC) and the Massive Array of Idle Disks (MAID). Different from MAID and PDC which store a complete file on the same disk, the Redundancy Array of Inexpensive Disks (RAID) stripes file into several parts and stores them on different disks to ensure higher parallelism, hence higher I/O performance. However, RAID faces more challenges on energy efficiency
and reliability issues. In order to evaluate the reliability of power-aware RAID, we
then develop a Weibull-based model–MREED. In this dissertation, we use MREED to model the reliability impacts of a famous energy efficiency storage mechanism– the Power-Aware RAID (PARAID). Thirdly, we focus on validation of two models–MINT and MREED. It is challenging to validate the accuracy of reliability models, since we are unable to watch certain energy-efficiency systems for a couple of decades due to its time consuming and experimental costs. We introduce validated storage system
simulator–DiskSim–to determine if our model and DiskSim agree with one another. In our validation process, we compare a file access trace in a real-world file system. Last part of of this dissertation focuses on improvement of energy-efficient parallel storage systems. We propose a strategy–Disk Swapping–to improve disk reliability by alternating disks storing data that is frequently accessed with disks holding less accessed data. In this part, we focus on studying reliability improvement of PDC and MAID. At last, we further improve disk reliability by introducing multiple disk
swapping strategy.
Embracing GenAI - A Strategic ImperativePeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
Synthetic Fiber Construction in lab .pptxPavel ( NSTU)
Synthetic fiber production is a fascinating and complex field that blends chemistry, engineering, and environmental science. By understanding these aspects, students can gain a comprehensive view of synthetic fiber production, its impact on society and the environment, and the potential for future innovations. Synthetic fibers play a crucial role in modern society, impacting various aspects of daily life, industry, and the environment. ynthetic fibers are integral to modern life, offering a range of benefits from cost-effectiveness and versatility to innovative applications and performance characteristics. While they pose environmental challenges, ongoing research and development aim to create more sustainable and eco-friendly alternatives. Understanding the importance of synthetic fibers helps in appreciating their role in the economy, industry, and daily life, while also emphasizing the need for sustainable practices and innovation.
A Strategic Approach: GenAI in EducationPeter Windle
Artificial Intelligence (AI) technologies such as Generative AI, Image Generators and Large Language Models have had a dramatic impact on teaching, learning and assessment over the past 18 months. The most immediate threat AI posed was to Academic Integrity with Higher Education Institutes (HEIs) focusing their efforts on combating the use of GenAI in assessment. Guidelines were developed for staff and students, policies put in place too. Innovative educators have forged paths in the use of Generative AI for teaching, learning and assessments leading to pockets of transformation springing up across HEIs, often with little or no top-down guidance, support or direction.
This Gasta posits a strategic approach to integrating AI into HEIs to prepare staff, students and the curriculum for an evolving world and workplace. We will highlight the advantages of working with these technologies beyond the realm of teaching, learning and assessment by considering prompt engineering skills, industry impact, curriculum changes, and the need for staff upskilling. In contrast, not engaging strategically with Generative AI poses risks, including falling behind peers, missed opportunities and failing to ensure our graduates remain employable. The rapid evolution of AI technologies necessitates a proactive and strategic approach if we are to remain relevant.
Biological screening of herbal drugs: Introduction and Need for
Phyto-Pharmacological Screening, New Strategies for evaluating
Natural Products, In vitro evaluation techniques for Antioxidants, Antimicrobial and Anticancer drugs. In vivo evaluation techniques
for Anti-inflammatory, Antiulcer, Anticancer, Wound healing, Antidiabetic, Hepatoprotective, Cardio protective, Diuretics and
Antifertility, Toxicity studies as per OECD guidelines
Honest Reviews of Tim Han LMA Course Program.pptxtimhan337
Personal development courses are widely available today, with each one promising life-changing outcomes. Tim Han’s Life Mastery Achievers (LMA) Course has drawn a lot of interest. In addition to offering my frank assessment of Success Insider’s LMA Course, this piece examines the course’s effects via a variety of Tim Han LMA course reviews and Success Insider comments.
COMP2710: Software Construction - Linked list exercises
1. COMP 2710 Software Construction
Linked List – Exercises
Dr. Xiao Qin
Department of Computer Science and
Software Engineering
Auburn University
http://www.eng.auburn.edu/~xqin
xqin@auburn.edu
2. Exercise 1
1-2
• Task 1: Define a structure named node, where there are two
items – (1) data whose type is int and (2) a pointer pointing
to the next node
• Task 2: Using typedef to define a new type (e.g., nodePtr)
of pointer pointing to node (i.e., node*)
• Task 3: Create a pointer (e.g., node_ptr) using the above new
data type
• Task 4: Allocate memory resource for the new pointer
• Task 5: Assign value (e.g., 10) to the node pointed by
node_ptr
3. Exercise 2: Print a list of nodes
struct node {
int data;
node *next;
};
typedef node* nodePtr;
void printList(nodePtr root);
What two cases should we consider?
4. Answer: Print a list of nodes
void printList(nodePtr root) {
nodePtr cur;
if (root == NULL)
cout << "This is an empty listn";
cur = root;
while (cur != NULL) {
cout << cur->data << endl;
cur = cur->next;
}
}
5. Exercise 3:
Insert a node to the head of the list
struct node {
int data;
node *next;
};
typedef node* nodePtr;
void insertNode(nodePtr& root, int info);
//Another possible prototype
void insertNode(nodePtr& root, nodePtr newNodePtr);
What is the difference between the above two prototypes?
How many cases should we consider? What are these cases?
6. Exercise 3 - Insert a node to the head of the list
1-6
struct node {
int data;
node *next;
};
typedef node* nodePtr;
void insertNode(nodePtr& root, int info);
root
cur_ptr
11
22 33
info
44
55
66
7. Exercise 3: Answer
Insert a node to the head of the list
void insertNode(nodePtr& root, int info) {
nodePtr cur_prt;
cur_ptr = new node; //Do not use this: new nodePtr
assert(cur_ptr != NULL); //Ensure that memory is allocatd
cur_ptr->data = info;
cur_ptr->next = NULL;
if (root == NULL) //For empty list, cur_ptr becomes the root
root = cur_prt;
else { //Insert cur as the root of the list
cur_ptr->next = root;
root = cur_ptr;
}
}
8. Exercise 4: Insert a node to the
end of the list
1-8
struct node {
int data;
node *next;
};
typedef node* nodePtr;
void appendNode(nodePtr& root, int info);
How many cases should we consider? What are these cases?
9. Exercise 4 - Insert a node to the end of the list
1-9
struct node {
int data;
node *next;
};
typedef node* nodePtr;
void appendNode(nodePtr& root, int info);
root
new_ptr
11
22 33
info
44
55
cur_ptr
6.16.1
6.26.2
10. void appendNode(nodePtr& root, int info) {
nodePtr new_ptr;
nodePtr cur_ptr;
new_ptr = new node; //Do not use this: new nodePtr
assert(new_Ptr != NULL); //Ensure that memory is allocatd
new_ptr->data = info;
new_ptr->next = NULL;
if (root == NULL) //For empty list, new_ptr becomes the root
root = new_ptr;
else { //Append the new node at the end of the list
cur_ptr = root;
while (cur_ptr->next != NULL)
cur_ptr = cur_ptr->next;
cur_ptr->next = new_ptr;
}
}
11. Exercise 5: Delete the head node
of the list
1-11
struct node {
int data;
node *next;
};
typedef node* nodePtr;
void deleteHead(nodePtr& root);
How many cases should we consider? What are these cases?
12. Exercise 5 - Delete the head node of the list
1-12
struct node {
int data;
node *next;
};
typedef node* nodePtr;
void deleteHead(nodePtr& root);
root
22
11 curPtr
33
13. void deleteHead(nodePtr& root) {
nodePtr cur_ptr;
if (root != NULL) {
cur_ptr = root; //Deleted node must be returned to OS
root = root->next;
delete cur_ptr;
}
else
cout << "This is an empty list. No deletion!n";
}
14. Review: Linked List
struct node {
int data;
node *next;
};
typedef node* nodePtr;
void insertNode(nodePtr& root, int info);
void appendNode(nodePtr& root, int info);
void deleteHead(nodePtr& root);
15. Exercise 6:
Delete the last node in the list
1-15
struct node {
int data;
node *next;
};
typedef node* nodePtr;
void deleteTail(nodePtr& root);
How many cases should we consider? What are these cases?
1.Implement the function
2.Write a test driver
16. Exercise 6 - Delete the last node in the list
1-16
struct node {
int data;
node *next;
};
typedef node* nodePtr;
void deleteTail(nodePtr& root);
root
11
22
33
pre_ptr cur_ptr
44
17. void deleteTail(nodePtr& root) {
nodePtr cur_prt, pre_ptr;
//There are three cases:
if (root == NULL) //Empty list
cout << "This is an empty list. No tail is deleted!n";
else {
if (root->next == NULL) { //List has one node
free(root); //or delete root;
root = NULL;
}
else { //List has more than one node
pre_ptr = root;
cur_ptr = root->next;
while (cur_ptr->next != NULL) {
pre_ptr = cur_ptr;
cur_ptr = cur_ptr->next;
}
pre_ptr->next = NULL;
delete cur_ptr; //or delete cur, pointing at the last node
}
}
}
18. Exercise 7:
Delete a specified node in the list
1-18
struct node {
int data;
node *next;
};
typedef node* nodePtr;
void deleteNode(nodePtr& root, int info);
How many cases should we consider? What are these cases?
1.Implement the function
2.Write a test driver
19. Exercise 7 - Delete a specified node in the list
1-19
void deleteNode(nodePtr& root, int info);
root
11
22
33
cur_ptr
44
pre_ptr
NULL
find
20. void deleteNode(nodePtr& root, int info) {
nodePtr cur_ptr, pre_ptr;
if (root == NULL) //Empty list
cout << "This is an empty list. No node is deleted!n";
else {
pre_ptr = NULL; cur_ptr = root;
while (cur_ptr != NULL) { //cur_ptr->next != NULL is Bug 1: coredump
if (cur_ptr->data != info) { //compare and does not match
pre_ptr = cur_ptr;
cur_ptr = cur_ptr->next;
}
else { //match and delete node pointed by cur
if (pre_ptr == NULL) { //cur is pointing to the first node
root = root->next;
delete cur_ptr;
cur_ptr = root;
}
else { //cur_ptr is NOT pointing to the first node
pre_ptr->next = cur_ptr->next;
delete cur_ptr;
cur_ptr = pre_ptr->next;
}
}
Editor's Notes
Programming Language: C or C++
Spring’15: slides 14-16 - See also Lec08c2-Lnked List Exercise 1.ppt
Empty List
Non-empty list
void printList(nodePtr root) {
nodePtr cur;
if (root == NULL)
cout &lt;&lt; &quot;This is an empty list\n&quot;;
cur = root;
while (cur != NULL) {
cout &lt;&lt; cur-&gt;data &lt;&lt; endl;
cur = cur-&gt;next;
}
}
Empty List
Non-empty list
void printList(nodePtr root) {
nodePtr cur;
if (root == NULL)
cout &lt;&lt; &quot;This is an empty list\n&quot;;
cur = root;
while (cur != NULL) {
cout &lt;&lt; cur-&gt;data &lt;&lt; endl;
cur = cur-&gt;next;
}
}
void insertNode(nodePtr& root, int info) {
nodePtr cur;
cur = new node; //Do not use this: new nodePtr
assert(cur != NULL); //Ensure that memory is allocatd
cur-&gt;data = info;
cur-&gt;next = NULL;
if (root == NULL) //If the list is empty, cur becomes the root
root = cur;
else { //Insert cur as the root of the list
cur-&gt;next = root;
root = cur;
}
}
void appendNode(nodePtr& root, int info) {
nodePtr cur;
nodePtr pre;
cur = new node; //Do not use this: new nodePtr
assert(cur != NULL); //Ensure that memory is allocatd
cur-&gt;data = info;
cur-&gt;next = NULL;
if (root == NULL) //If the list is empty, cur becomes the root
root = cur;
else { //Append the new node at the end of the list
pre = root;
while (pre-&gt;next != NULL)
pre = pre-&gt;next;
pre-&gt;next = cur;
}
}
void insertNode(nodePtr& root, int info) {
nodePtr cur;
cur = new node; //Do not use this: new nodePtr
assert(cur != NULL); //Ensure that memory is allocatd
cur-&gt;data = info;
cur-&gt;next = NULL;
if (root == NULL) //If the list is empty, cur becomes the root
root = cur;
else { //Insert cur as the root of the list
cur-&gt;next = root;
root = cur;
}
}
void appendNode(nodePtr& root, int info) {
nodePtr cur;
nodePtr pre;
cur = new node; //Do not use this: new nodePtr
assert(cur != NULL); //Ensure that memory is allocatd
cur-&gt;data = info;
cur-&gt;next = NULL;
if (root == NULL) //If the list is empty, cur becomes the root
root = cur;
else { //Append the new node at the end of the list
pre = root;
while (pre-&gt;next != NULL)
pre = pre-&gt;next;
pre-&gt;next = cur;
}
}
void appendNode(nodePtr& root, int info) {
nodePtr cur;
nodePtr pre;
cur = new node; //Do not use this: new nodePtr
assert(cur != NULL); //Ensure that memory is allocatd
cur-&gt;data = info;
cur-&gt;next = NULL;
if (root == NULL) //If the list is empty, cur becomes the root
root = cur;
else { //Append the new node at the end of the list
pre = root;
while (pre-&gt;next != NULL)
pre = pre-&gt;next;
pre-&gt;next = cur;
}
}
void deleteHead(nodePtr& root);
void deleteHead(nodePtr& root) {
nodePtr cur;
if (root != NULL) {
cur = root; //Deleted node must be returned to the OS
root = root-&gt;next;
delete cur;
}
else
cout &lt;&lt; &quot;This is an empty list. No head is deleted!\n&quot;;
}
void appendNode(nodePtr& root, int info) {
nodePtr cur;
nodePtr pre;
cur = new node; //Do not use this: new nodePtr
assert(cur != NULL); //Ensure that memory is allocatd
cur-&gt;data = info;
cur-&gt;next = NULL;
if (root == NULL) //If the list is empty, cur becomes the root
root = cur;
else { //Append the new node at the end of the list
pre = root;
while (pre-&gt;next != NULL)
pre = pre-&gt;next;
pre-&gt;next = cur;
}
}
void insertNode(nodePtr& root, int info) {
nodePtr cur;
cur = new node; //Do not use this: new nodePtr
assert(cur != NULL); //Ensure that memory is allocatd
cur-&gt;data = info;
cur-&gt;next = NULL;
if (root == NULL) //If the list is empty, cur becomes the root
root = cur;
else { //Insert cur as the root of the list
cur-&gt;next = root;
root = cur;
}
}
void deleteTail(nodePtr& root) {
nodePtr cur, pre;
if (root == NULL) //Empty list
cout &lt;&lt; &quot;This is an empty list. No tail is deleted!\n&quot;;
else {
if (root-&gt;next == NULL) { //List has one node
free(root);
root = NULL;
}
else { //List has more than one node
pre = root;
cur = root-&gt;next;
while (cur-&gt;next != NULL) {
pre = cur;
cur = cur-&gt;next;
}
pre-&gt;next = NULL;
free(cur); //delete cur, which is pointing at the last node
}
}
}
void appendNode(nodePtr& root, int info) {
nodePtr cur;
nodePtr pre;
cur = new node; //Do not use this: new nodePtr
assert(cur != NULL); //Ensure that memory is allocatd
cur-&gt;data = info;
cur-&gt;next = NULL;
if (root == NULL) //If the list is empty, cur becomes the root
root = cur;
else { //Append the new node at the end of the list
pre = root;
while (pre-&gt;next != NULL)
pre = pre-&gt;next;
pre-&gt;next = cur;
}
}
void deleteNode(nodePtr& root, int info) {
nodePtr cur, pre;
if (root == NULL) //Empty list
cout &lt;&lt; &quot;This is an empty list. No node is deleted!\n&quot;;
else {
pre = NULL;
cur = root;
while (cur != NULL) { //cur-&gt;next != NULL is Bug 1 - core dump occur
if (cur-&gt;data != info) { //compare and does not match
pre = cur;
cur = cur-&gt;next;
}
else { //match and delete node pointed by cur
if (pre == NULL) { //cur is pointing to the first node
root = root-&gt;next;
delete cur;
cur = root;
}
else { //cur is NOT pointing to the first node
pre-&gt;next = cur-&gt;next;
delete cur;
cur = pre-&gt;next;
}
}
}
//Bug 2: With the following two statement, only when delete one-node list, can core dump occur
//pre-&gt;next = NULL; //adding these two statements - core dump occur
//delete cur; //delete cur, which is pointing at the last node
}
}
void appendNode(nodePtr& root, int info) {
nodePtr cur;
nodePtr pre;
cur = new node; //Do not use this: new nodePtr
assert(cur != NULL); //Ensure that memory is allocatd
cur-&gt;data = info;
cur-&gt;next = NULL;
if (root == NULL) //If the list is empty, cur becomes the root
root = cur;
else { //Append the new node at the end of the list
pre = root;
while (pre-&gt;next != NULL)
pre = pre-&gt;next;
pre-&gt;next = cur;
}
}