الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

How You Add A Node In The Middle Of Linked List

بدأه moooooooon في 22 مارس 2008 · 1 رد · 800 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

الــــــــــــــسلام عليكم و رحمـــــــــــة الله و بركاته

هذا برنامج لإضافة نود من البدايه و النهايه

سؤالي هو كيف أضيف كود لهذا البرنامج بحيث يضيف نود آخر و لكن في الوسط

هذا البرنامج

class IntSLLNode {
	public int info;
	public IntSLLNode next=null;
	public IntSLLNode()
	{
	}
	public IntSLLNode(int el)
	{
		info=el;
	}
	public IntSLLNode(int el,IntSLLNode ref)
	{
		info=el; next=ref;
	}
}
class IntSLList
{
	protected IntSLLNode head,tail;
	public IntSLList()
	{
		head=tail=null;
	}
	public boolean isEmpty()
	{
		return head==null;
	}
	public void addToHead(int el)
	{
		head=new IntSLLNode(el,head);
		if(tail==null)
		tail=head;
	}
	public void addToTail(int el)
	{
		if(!isEmpty())
		{
			tail.next=new IntSLLNode(el);
			tail=tail.next;
		}
		else head=tail=new IntSLLNode(el);
	}

	public void printAll()
{
	for(IntSLLNode tmp=head;tmp!=null;tmp=tmp.next)
	System.out.print(tmp.info+" ");
}
}
class IntSLListMain
{
	public static void main(String args[])
	{
		System.out.println("The Linked List ....");
		IntSLList l=new IntSLList();
		l.printAll();
		System.out.println("The Linked after add to head & tail ...");
		l.addToHead(7);
		l.addToTail(5);
		l.addToHead(3);
		l.printAll();
	}
}

تم تعديل هذه المشاركة بواسطة moooooooon في 22 مارس 2008 في 20:56

#2

ارجوا ان تفيدك المرفقات واذا اردت شرح سوف اقوم بشرحه لك

link.rar

مواضيع مشابهة