The following is the code for a linked list that I am supposed to build on for my project (no main(), just the function definitons) -the header file for the process_list class is not included:
Code:
#include <iostream>
#include <stdarg.h>
#include "scheduling.h"
using namespace std;
typedef unsigned char boolean;
typedef int* int_ptr;
// default constructor for head of list
process_list::process_list() {
m_curr = this;
m_prev = NULL;
m_next = NULL;
}
//constructor for extra nodes
process_list::process_list(process_list* prev)
{
m_prev = prev;
m_next = NULL;
}
//inserts a new process with data given
void process_list::insert(int temp_pid, int temp_tarq, int temp_prio, int temp_tncpu, int_ptr temp_cpu_burst_lenth, int_ptr temp_IO_burst_lenth)
{
while (m_curr->get_next() != NULL)
m_curr = m_curr->get_next();
m_curr->set_data(temp_pid, temp_tarq, temp_prio, temp_tncpu, temp_cpu_burst_lenth, temp_IO_burst_lenth);
m_curr->set_next(new process_list(m_curr));
}
//Fetch PID functions
int process_list::get_pidE1()
{
return pid;
}
int process_list::get_pid()
{
return m_curr->get_pidE1();
}
//Fetch tarq functions
int process_list::get_tarqE1()
{
return tarq;
}
int process_list::get_tarq()
{
return m_curr->get_tarqE1();
}
//Fetch Prio functions
int process_list::get_prioE1()
{
return prio;
}
int process_list::get_prio()
{
return m_curr->get_prioE1();
}
//Fetch tncpu functions
int process_list::get_tncpuE1()
{
return tncpu;
}
int process_list::get_tncpu()
{
return m_curr->get_tncpuE1();
}
//Fetch cpu_burst_lenth functions
int_ptr process_list::get_cpu_burst_lenthE1()
{
return cpu_burst_lenth;
}
int_ptr process_list::get_cpu_burst_lenth()
{
return m_curr->get_cpu_burst_lenthE1();
}
//Fetch IO_burst_lenth functions
int_ptr process_list::get_IO_burst_lenthE1()
{
return IO_burst_lenth;
}
int_ptr process_list::get_IO_burst_lenth()
{
return m_curr->get_IO_burst_lenthE1();
}
// set process information function
void process_list::set_data(int temp_pid, int temp_tarq, int temp_prio, int temp_tncpu, int_ptr temp_cpu_burst_lenth, int_ptr temp_IO_burst_lenth)
{
pid = temp_pid;
tarq = temp_tarq;
prio = temp_prio;
tncpu = temp_tncpu;
cpu_burst_lenth = temp_cpu_burst_lenth;
IO_burst_lenth = temp_IO_burst_lenth;
}
//returns a pointer to the previous process
process_list* process_list::get_prev()
{
return m_prev;
}
//returns a pointer to the next process
process_list* process_list::get_next()
{
return m_next;
}
//add a new process to the list
void process_list::set_next(process_list* process)
{
m_next = process;
}
//sets m_curr pointer back to the start of the list
void process_list::reset()
{
m_curr = this;
}
//moves m_curr to the next process in the list
void process_list::next()
{
m_curr = m_curr->get_next();
}
//moved m_curr to the previous process in the list
void process_list::prev()
{
m_curr = m_curr->get_prev();
}
//check for end
boolean process_list::is_end()
{
return m_curr->get_next() == NULL ? 1 : 0;
}
//check for biginning
boolean process_list::is_beginning()
{
return m_curr == NULL ? 1 : 0;
}
//check if any entries have been added to the list
boolean process_list::is_empty()
{
return m_curr->get_next() == m_curr->get_prev() ? 1 : 0;
}
Now my questions:
1) In the default constructor, what does m_curr = this; do?
2) Why doesn't the constructor for extra nodes have a m_curr field?
3) What's the difference between a function, say get_tarq(), and the one with the same name but with an E1 at the end (get_tarqE1())?
4) Which function of stdarg.h is used in this code?
5) Is this an efficient code? What do you think of the style of coding?
The above questions arose because I didn't write the code. Any help is greatly appreciated.