i need help making an add function for an array.
i know how to initialize it and have it started. when i add content into the array, i need to add it as a linked list. i have my function for the linked list completed alrady. if anyone can help point me in the right direction, i would greatly appreciate it. thank you.
linked list code
#include <iostream>
#include <string>
using namespace std;
//new class for studentnode
class node
{
public:
string data;
node * next;
string university;
int id;
}
;
//new class for studentlist
class studentlist
{
private:
node * start;
public:
studentlist()
{
start = NULL;
}
// function to add a new student to list
void add(string stu, string univ, int id)
{
//create a new node
node * somenode;
somenode = new node;
//put student in the new node!
somenode->data = stu;
somenode->university = univ;
somenode->id = id;
//put new node at front of list!
somenode->next = start;
start = somenode;
}
//function to a specified student, if not traverse the list until found.
void getStudent (int id)
{
node* current;
current = start;
while(current!=NULL)
{
if(current->id == id)
{
cout << "Using the ID, we found the student in the system!! "<< endl;
cout << "Student Name: " << current->data << endl;
cout << "School Attending: " << current->university <<endl;
break;
}
current = current->next;
}
}
//display all the items in the list
void print()
{
node * current;
current = start;
//loop through all nodes, each time doing something
while(current != NULL )
{
//display the data of the current node
cout << "Basic Information Available" << endl;
cout << current->data << endl;
cout << current->university << endl;
cout << current->id << endl;
//move current to next node
current = current->next;
}
}
};
and here is what i have so far, for the array initialization.
class studentTable
{
private:
studentList * table; //an array of studentLists
int tableSize; //size of the array
public:
//this is what i need help implementing!!
void add(student s);
}
if there are any more questions. plese let me know.
thanks