hey guys can someone help me with this i am stuck here where do i define a loop to add more nodes in the linked list or any other way to define nodes itslef in the code
class Program
{
static void Main(string[] args)
{
List obj = new List();
obj.addnode();
obj.traverse();
}
class LinkedListNode
{
public int rollnumber;
public string name;
public int score1;
public int score2;
public int score3;
public int average;
public LinkedListNode next;
}
class List
{
LinkedListNode start;
public List()
{
start = null;
}
public void addnode()
{
string nm;
int rollno;
int s1;
int s2;
int s3;
int avg;
LinkedListNode previous, current;
previous = start;
current = start;
Console.WriteLine("\nenter the name of the student");
nm = Console.ReadLine();
Console.WriteLine("\nenter the roll number of the student");
rollno = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nenter score1:");
s1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nenter score2:");
s2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nenter score3:");
s3 = Convert.ToInt32(Console.ReadLine());
avg = (s1 + s2 + s3) / 3;
LinkedListNode newnode = new LinkedListNode();
newnode.rollnumber = rollno;
newnode.name = nm;
newnode.score1 = s1;
newnode.score2 = s2;
newnode.score3 = s3;
newnode.average = avg;
newnode.next = start;
start = newnode;
return;
if (start == null || rollno >= start.rollnumber)
{
if ((start != null) && (rollno == start.rollnumber))
{
Console.WriteLine("\nduplicate roll numbers not allowed");
return;
}
newnode.next = start;
start = newnode;
return;
}
while ((current != null) && (rollno >= current.rollnumber))
{
previous = current;
current = current.next;
}
newnode.next = current;
previous.next = newnode;
}
public void traverse()
{
if (listEmpty())
{
Console.WriteLine("\nlist is empty");
}
else
{
Console.WriteLine("\nRoll No." + " " + "Name" + "\t" + "score-1" + "\t" + "score-2" + "\t" + "score-3" + "\t " + "Average");
Console.ReadLine();
LinkedListNode currentnode;
for (currentnode = start; currentnode != null; currentnode = currentnode.next)
{
Console.WriteLine("\n" + currentnode.rollnumber + " \t " + currentnode.name + " \t " + currentnode.score1 + " \t " + currentnode.score2 + " \t " + currentnode.score3 + " \t " + currentnode.average);
Console.ReadLine();
}
}
}
public bool listEmpty()
{
if (start == null)
return true;
else
return false;
}
}
}
}