Implementation [LINKED LIST]

hello there:)
i have this problem and i dont know how to continue..pls help and guide me.i have my incomplete code below.ive tried my whole effort but it doesnt work.i have research and comprehend lots of codes.my mind cannot access the process - ACCESS DEnieD! ;)

*A program that would store the ff:

Student number
student last name
student first name
gender
year level

requirements:
1. add record at the end of the list
2.delete a record(by student number0
3. search by student number
4. display all unsorted records
5.display all year level
6.SORT by last name and first name(use selection sort)
3.

[code]
#include

using namespace std;

struct node
{
char studentnumber[5];
char studentname[20];
node *nxt;// Pointer to next node
};

node *start_ptr = NULL;
node *current; // Used to move along the list


void add_record()
{ node *temp, *temp2; // Temporary pointers


// Reserve space for new node and fill it with data

temp = new node;

cout<<"Student number: ";
cin>>temp->studentnumber;
cout<<"Student name: ";
cin>>temp->studentname;
temp->nxt = NULL;
// Set up link to this node
if (start_ptr == NULL)
{ start_ptr = temp;
current = start_ptr;
}
else
{ temp2 = start_ptr;
// We know this is not NULL - list not empty!
while (temp2->nxt != NULL)
{ temp2 = temp2->nxt;
// Move to next link in chain
}
temp2->nxt = temp;
}
}

void display_records()
{ node *temp;
temp = start_ptr;
cout << endl;
if (temp == NULL)
cout << "The list is empty!" << endl;
else
{ while (temp != NULL)
{ // Display details for what temp points to
cout<< "Student Number: "<<temp->studentnumber;
cout<< "Student Name: "<<temp->studentname;

if (temp == current)
cout << " <-- Current node";
cout << endl;
temp = temp->nxt;

}
cout << "End of list!" << endl<<endl;
}
}


int main()
{
int input;
menu:
cout<<"[1] ADD a record";
cout<<"
[2] DELETE a record";
cout<<"
[3] SEARCH by student number";
cout<<"
[4] DISPLAY a record";
cout<<"
[5] SORT by name";
cout<<endl;
cout<<"what's your choice?";
cin>>input;

switch(input)
{
case 1:
add_record();
goto menu;
break;

case 4:
display_records();
goto menu;
break;
}

system("pause");
}

[/code]

if you have time please help me and my colleagues.thanks!:D

Comments

  • Part of your problem is the way you designed your struct. When you look at the requirements, it mentions last name as distinct from first name, so instead of creating just char name[] variable create two separate variables for first and last names. That will make sorting easier. Also, think about ways of separating the student structure from the list node structure.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion