Click here to Skip to main content
15,908,020 members
Home / Discussions / C#
   

C#

 
AnswerRe: Extracting regex from string Pin
Eddy Vluggen21-Apr-19 0:37
professionalEddy Vluggen21-Apr-19 0:37 
AnswerRe: Extracting regex from string Pin
Gerry Schmitz21-Apr-19 3:07
mveGerry Schmitz21-Apr-19 3:07 
AnswerRe: Extracting regex from string Pin
#realJSOP21-Apr-19 5:12
professional#realJSOP21-Apr-19 5:12 
GeneralRe: Extracting regex from string Pin
jschell21-Apr-19 7:48
jschell21-Apr-19 7:48 
GeneralRe: Extracting regex from string Pin
#realJSOP21-Apr-19 11:45
professional#realJSOP21-Apr-19 11:45 
GeneralRe: Extracting regex from string Pin
jschell27-Apr-19 6:11
jschell27-Apr-19 6:11 
GeneralRe: Extracting regex from string Pin
ormonds21-Apr-19 12:19
ormonds21-Apr-19 12:19 
AnswerRe: Extracting regex from string Pin
jschell21-Apr-19 7:52
jschell21-Apr-19 7:52 
AnswerRe: Extracting regex from string Pin
Luc Pattyn22-Apr-19 15:45
sitebuilderLuc Pattyn22-Apr-19 15:45 
QuestionI need help with console app in C# Pin
User 1428799220-Apr-19 11:24
User 1428799220-Apr-19 11:24 
AnswerRe: I need help with console app in C# (old mac donald had a farm) Pin
OriginalGriff20-Apr-19 11:31
mveOriginalGriff20-Apr-19 11:31 
AnswerRe: I need help with console app in C# (old mac donald had a farm) Pin
Dave Kreskowiak20-Apr-19 13:01
mveDave Kreskowiak20-Apr-19 13:01 
AnswerRe: I need help with console app in C# (old mac donald had a farm) Pin
Luc Pattyn20-Apr-19 15:27
sitebuilderLuc Pattyn20-Apr-19 15:27 
GeneralRe: I need help with console app in C# (old mac donald had a farm) Pin
Dave Kreskowiak20-Apr-19 15:54
mveDave Kreskowiak20-Apr-19 15:54 
Questionmy programming language is c#.I have a form in tabpage. if i want to resize the form like visual studio.what the... I should doing Pin
Member 1432102120-Apr-19 5:47
Member 1432102120-Apr-19 5:47 
AnswerRe: my programming language is c#.I have a form in tabpage. if i want to resize the form like visual studio.what the... I should doing Pin
OriginalGriff20-Apr-19 6:03
mveOriginalGriff20-Apr-19 6:03 
GeneralRe: my programming language is c#.I have a form in tabpage. if i want to resize the form like visual studio.what the... I should doing Pin
Member 1432102120-Apr-19 6:15
Member 1432102120-Apr-19 6:15 
GeneralRe: my programming language is c#.I have a form in tabpage. if i want to resize the form like visual studio.what the... I should doing Pin
OriginalGriff20-Apr-19 6:24
mveOriginalGriff20-Apr-19 6:24 
AnswerRe: my programming language is c#.I have a form in tabpage. if i want to resize the form like visual studio.what the... I should doing Pin
Gerry Schmitz20-Apr-19 6:06
mveGerry Schmitz20-Apr-19 6:06 
GeneralRe: my programming language is c#.I have a form in tabpage. if i want to resize the form like visual studio.what the... I should doing Pin
OriginalGriff20-Apr-19 6:18
mveOriginalGriff20-Apr-19 6:18 
GeneralRe: my programming language is c#.I have a form in tabpage. if i want to resize the form like visual studio.what the... I should doing Pin
Gerry Schmitz20-Apr-19 8:22
mveGerry Schmitz20-Apr-19 8:22 
AnswerRe: my programming language is c#.I have a form in tabpage. if i want to resize the form like visual studio.what the... I should doing Pin
Simon_Whale20-Apr-19 6:14
Simon_Whale20-Apr-19 6:14 
AnswerRe: my programming language is c#.I have a form in tabpage. if i want to resize the form like visual studio.what the... I should doing Pin
BillWoodruff23-Apr-19 7:49
professionalBillWoodruff23-Apr-19 7:49 
QuestionMerge Sort linked list Pin
Member 1431822319-Apr-19 12:23
Member 1431822319-Apr-19 12:23 
C#
<pre>using System;

namespace DoublyLinkedList
{
	class Link<T> : IComparable<Link<T>> where T : IComparable<T>
	{
		public Link(T data)
		{
			Data = data;
			Next = null;
			Previous = null;
		}
		public T Data {get;set;}
		public Link<T> Next {get;set;}
		public Link<T> Previous {get;set;}
		public int CompareTo(Link<T> other) {return Data.CompareTo(other.Data);}
		public int CompareTo(T other) {return Data.CompareTo(other);}
		public void DisplayLink()
			{Console.Write(Data.ToString() + " ");}
	}
}

C#
<pre>using System;

namespace DoublyLinkedList
{
	class DoublyLinkedList<T> where T :IComparable<T>
	{
		public Link<T> First {get;set;}
		public Link<T> Last {get;set;}
		public DoublyLinkedList() {First = null;Last = null;}
		public Link<T> Find(T key)
		{
			Link<T> current = First;
			while(current.CompareTo(key) != 0)
			{
				if(current.Next == null)
					return null;
				else
					current = current.Next;
			}
			return current;
		}
		public bool IsEmpty()
			{return First == null;}
		public void InsertFirst(T dd)
		{
			Link<T> NewLink = new Link<T>(dd);
			if(IsEmpty())
				Last = NewLink;
			else
				First.Previous = NewLink;
			NewLink.Next = First;
			First = NewLink;
		}
		public void InsertLast(T dd)
		{
			Link<T> NewLink  = new Link<T>(dd);
			if(IsEmpty())
				First = NewLink;
			else
			{
				Last.Next = NewLink;
				NewLink.Previous = Last;
			}
			Last = NewLink;
		}
		public Link<T> DeleteFirst()
		{
			if(IsEmpty())
				return null;
			Link<T> temp = First;
			if(First.Next == null)
				Last = null;
			else
				First.Next.Previous = null;
			First = First.Next;
			return temp;
		}
		public Link<T> DeleteLast()
		{
			if(IsEmpty())
				return null;
			Link<T> temp = Last;
			if(First.Next == null)
				First = null;
			else
				Last.Previous.Next = null;
			Last = Last.Previous;
			return temp;
		}
		public bool InsertAfter(T key,T dd)
		{
			Link<T> current = Find(key);
			if(current == null)
				return false;
			Link<T> NewLink = new Link<T>(dd);
			NewLink.Next = current.Next;
			if(current.Next == null)
				Last = NewLink;
			else
				current.Next.Previous = NewLink;
			NewLink.Previous = current;
			current.Next = NewLink;
			return true;
		}
		public Link<T> DeleteKey(T key)
		{
			Link<T> current = Find(key);
			if(current == null)
				return null;
			if(current.Previous == null)
				First = current.Next;
			else
				current.Previous.Next = current.Next;
			if(current.Next == null)
				Last = current.Previous;
			else
				current.Next.Previous = current.Previous;
			return current;
		}
		public void DisplayForward()
		{
			Console.Write("List (first-->last): ");
			Link<T> current = First;
			while(current != null)
			{
				current.DisplayLink();
				current = current.Next;
			}
			Console.WriteLine("");
		}
		public void DisplayBackward()
		{
			Console.Write("List (last-->first): ");
			Link<T> current = Last;
			while(current != null)
			{
				current.DisplayLink();
				current = current.Previous;
			}
			Console.WriteLine("");
		}
		// Functions for sorting
		public void Split(ref DoublyLinkedList<T> L1,ref DoublyLinkedList<T> L2)
		{
			Link<T> p = First;
			Link<T> q = Last;
			while(p != q && p.Next != q)
			{
				p = p.Next;
				q = q.Previous;
			}
			if(p == null || p.Next == null)
			{
				L1.First = First;
				L1.Last = Last;
				L2.First = null;
				L2.Last = null;
			}
			else
			{
				q = p.Next;
				p.Next = null;
				q.Previous = null;
				L1.First = First;
				L1.Last = p;
				L2.First = q;
				L2.Last = Last;
			}
		}
		public void Merge(DoublyLinkedList<T> L1,DoublyLinkedList<T> L2)
		{
			Link<T> p,q;
			First = null;
			Last = null;
			// Assume that both lists ars non empty and set head of result list 
			if(L1.First != null && L2.First != null)
			{
				if(L1.First.CompareTo(L2.First) <= 0) 
				{
					p = L1.First;
					if(L1.First.Next == null)
						L1.Last = null;
					else
						L1.First.Next.Previous = null;
					L1.First = L1.First.Next;
					p.Next = null;
					First = p;
					Last = p;
				}
				else
				{
					q = L2.First;
					if(L2.First.Next == null)
						L2.Last = null;
					else
						L2.First.Next.Previous = null;
					L2.First = L2.First.Next;
					q.Next = null;
					First = q;
					Last = q;
				}
			}
			/* Compare key values from current nodes of both linked list 
			   and append node with less key value to result list */
			while(L1.First != null && L2.First != null)
			{
				if(L1.First.CompareTo(L2.First) <= 0)
				{
					p = L1.First;
					if(L1.First.Next == null)
						L1.Last = null;
					else
						L1.First.Next.Previous = null;
					L1.First = L1.First.Next;
					p.Next = null;
					Last.Next = p;
					p.Previous = Last;
					Last = p;
				}
				else
				{
					q = L2.First;
					if(L2.First.Next == null)
						L2.Last = null;
					else
						L2.First.Next.Previous = null;
					L2.First = L2.First.Next;
					q.Next = null;
					Last.Next = q;
					q.Previous = Last;
					Last = q;
				}
			}
			// Concatenate rest of the list to result list;	
			if(Last != null)
				Last.Next = L1.First;
			else
				First = L1.First;
			if(L1.First != null)
			{
				L1.First.Previous = Last;
				Last = L1.Last;
			}
			if(Last != null)
				Last.Next = L2.First;
			else
				First = L2.First;
			if(L2.First != null)
			{
				L2.First.Previous = Last;
				Last = L2.Last;
			}
		}
		public void MergeSort()
		{
			DoublyLinkedList<T> h1 = new DoublyLinkedList<T>();
			DoublyLinkedList<T> h2 = new DoublyLinkedList<T>();
			if(First != null && First.Next != null)
			{
				Split(ref h1,ref h2);
				h1.MergeSort();
				h2.MergeSort();
				Merge(h1,h2);
			}
		}
	}
}


How can I avoid new operator inside MergeSort function
I translated Lafore List and wrote Merge Sort function


AnswerRe: Merge Sort linked list Pin
#realJSOP19-Apr-19 12:38
professional#realJSOP19-Apr-19 12:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.