[go: up one dir, main page]

0% found this document useful (0 votes)
13 views2 pages

MaxInChain and Recursion

The document contains a C# program that defines a linked list structure using the Intnode class. It includes methods for printing the chain of nodes, finding the maximum value in the chain, and a method to create a linked list from an array. The main method demonstrates the functionality by creating a linked list from an array of integers and printing the maximum value found in the list.

Uploaded by

cheesycray991
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views2 pages

MaxInChain and Recursion

The document contains a C# program that defines a linked list structure using the Intnode class. It includes methods for printing the chain of nodes, finding the maximum value in the chain, and a method to create a linked list from an array. The main method demonstrates the functionality by creating a linked list from an array of integers and printing the maximum value found in the list.

Uploaded by

cheesycray991
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

using System;

using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp19
{
public class Intnode
{
private int info;
private Intnode next;

public Intnode(int info)


{
this.info = info;
}
public Intnode(int info, Intnode next)
{
this.info = info;
this.next = next;
}
public int Getinfo()
{
return info;
}
public Intnode Getnext()
{
return next;
}
public override string ToString()
{
return info.ToString();
}
}
public class NodeToolsRecursive
{
public static void PrintChain(Intnode node)
{
if (node == null)
{
Console.WriteLine("null");
return;
}
Console.Write(node.ToString() + " -> ");
PrintChain(node.Getnext());
}
public static int MaxInChain(Intnode node)
{
if (node == null)
return int.MinValue;
return Math.Max(node.Getinfo(), MaxInChain(node.Getnext()));
}
}
public class Program
{
public static Intnode MinMax(Intnode node)
{
int min = int.MinValue;
int max = int.MaxValue;
while (node != null)
{
max = Math.Max(max, node.Getinfo());
min = Math.Min(min, node.Getinfo());
node = node.Getnext();
}
return new Intnode(min, new Intnode(max));
}
public static Intnode Bruh(int[] a)
{
Intnode answer = null;
for (int i = a.Length - 1; i >= 0; i--)
answer = new Intnode(a[i], answer);
return answer;
}
public static void Main(string[] args)
{
int[] arr = { -1, -65, -3, -234, -23465, -14, -67 };
Intnode bruh = Bruh(arr);
int man = NodeToolsRecursive.MaxInChain(bruh);
Console.WriteLine(man);
}
}
}

You might also like