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

singly linked list

بدأه همـــس الليل في 31 أكتوبر 2011 · 15 رد · 764 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

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

عندي برنامج بالsingly linked list عبارةعن اضافه كلمات ومعانيها

ومن المطلوب اني اسوي بحث بال pattern

يعني المستخدم حيدخل مثلا حرف الالف

وينطبع كل الكلمات اللي تبدا بحرق الالف ومعانيها

والكلمة ومعناها اضفتها في node وحده

كيف حقدر اسوي ميثود عملية البحث

والاستاذه قالت بامكانكم تستخدموا method start with

ياليت احد يساعدني

تم تعديل هذه المشاركة بواسطة همـــس الليل في 31 أكتوبر 2011 في 19:29

#2

هل بشترط الحل بواسطة singly linked list ؟؟

إذا نظــرتَ نيـوب اللـّيـثِ بـارزةً         فـلا تظــنَنَ أَنَّ اللـّيـــثَ يبْتسـِـــمُ


 


 


رسم المخططات البيانية بواسطة الجافا


 


كتاب تحليل وتصميم نظم المعلومات


#3

هل قمتي ببرمجة single linked list أم ماذا؟

أين محاولاتك في الموضوع؟

تحياتي

حزمة المحرك الإصدارة 0.8

أي أحد يجد أني ظلمته فليراسلني

وبإذن الله لو كان له حق سيأخذه

728x90.png

#4

ايوا حليت البرنامج

import java.util.Scanner;//program uses Scanner
public class Dictionary {

    public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
  boolean Y = true;
  boolean N = false;
    do{
    System.out.println("***********Quran Word E-Dictionary  ***********");
    System.out.println("1-insert (add) new word");
    System.out.println("2-Delete the word");
    System.out.println("3-Search for meaning ");
    System.out.println("3-Search with pattren ");
    System.out.println("4-Displaying all words");
    System.out.println("5-Exit");
    System.out.println("\n*Enter you chois ?");

    int chois = scan.nextInt();
    switch (chois) {
        case 1:{
                 AddFir();
        }
        break;
        case 2:{
                 DeleteANode();
        }
        break;
        case 3:{
            SearchForMeaning ();
        }break;
        case 4:{
            //ShowAllBooks(array,limit);
        }
        case 5:{
            display();
        }break;
        default:            System.out.println("XXXXXXX Rong chois XXXXXX");
            break;}
            System.out.println("do you want to choose from the menu again? enter Y for yes,or N for no");
    }while(N);
    }//end of main
//*************************************  All Methods  **************************
    Word call = new Word();
Word Head,Tail,temp, a,prev,current,previos;
 Scanner scan1 = new Scanner(System.in);
public void Dictionary (){
    Head = null;
    Tail=null;
}
int count;
//*******************************  inseart element at last ********************
      void AddFirst(){

    Word newNode = new Word ();

    System.out.println("Enter the word you want to enter!");
   newNode.setWord(scan1.nextLine());

        System.out.println("Enter the word you want to enter!");
   newNode.setMeaning(scan1.nextLine());

   newNode.setNext(Head);
   if(Head==null)
   Tail=newNode;

   Head=newNode;
   count ++;
}
//*******************************  remove from all cases ********************
    public void DeleteANode()        //<-- i thought it  was funny :)
{
   System.out.println("Enter the word you want to delete ");  // faaaaaaaaalse
  // Word newNode =new Word();
       String  DeleteW  = scan1.nextLine();
      // while(getWord().equalsIgnoreCase(DeleteW))
            temp = Head ;
          //while(Head.getWord().equalsIgnoreCase(DeleteW))

                if(Head == null)
      System.out.println("error the list is empty");
       else
       { //search
                     while(temp.getWord().equals(DeleteW))
                     {
           if(Head.getNext() == null)
           {
               Head=null;
           }
           else
           {
               if((Head.getNext() != null) && (Head.getNext() != Tail))
                   {
                   String  y=Head.getWord();
                   Head=Head.getNext();           //****
                 }
               else
               {
                  if(temp.getNext()!=null)
                      temp.setPrevious(null) ;

                   Head =prev ;
                while( prev.getNext()!=temp)
                    prev=prev.getNext();

                if(prev.getNext().getWord().equals( DeleteW))
                   prev.setNext(temp.getNext());
               }
                         }
           }
       }
    }

//---------------------------------- Search Meaning ---------------------------
   void SearchForMeaning (){
   System.out.println("Enter the you want to delet ");     // true
   String Search = scan1.nextLine();
     if (Head==null)
     System.out.println("error the list is empty");
     Word currentNode=Head;

     while(currentNode.getMeaning().equalsIgnoreCase(Search))
     {
         if(currentNode.getNext()!= null){
             currentNode=currentNode.getNext();
             System.out.println(currentNode.getMeaning());}
         else
             System.out.println("Didn't find the word");
     }
     }
   //----------------------------------Search By pattren ----------------------
   void SearchWithPattern(){
      System.out.println("Enter the you want to search ");     // true
   String SearchP = scan1.nextLine();

   if(a.getWord().startsWith(SearchP))
   }


//----------------------------------Display Word-------------------------------
 void display(){
    System.out.println("the list is(first-->last:");
    Word Node =Head;
    while(Node!=null)                           // faaaaaaaaalse
    {
        System.out.println( Node.getWord()+ Node.getMeaning() +"\n");
        Node=Node.getNext();
    }
    }

 public String toString(){

return (getWord()+ getMeaning() +"\n");

 }
}//end of class Dictionary

public class Word {

    public  String word;
    public  String meaning;
    private static Word next;
    Object  DeleteW;


     void Word() //zero argument constructor
    { word = null;
      meaning = null;
     }
     void Word (String word2,String meaning2, Word NEXT )
      { word = word2;
        meaning = meaning2;
        next =  NEXT;
      }//end constructor
//***********************************************sets**************************
     void setWord (String NewWord)
      {
        word = NewWord;
      }
     void setMeaning (String NewMeaning)
      {
        meaning = NewMeaning ;
      }
     void setNext (Word Next)
      {
        next = Next ;
      }
//***********************************************gets**************************
     public String getWord()
      {
        return word;
      }
    public  String getMeaning()
      {
        return meaning;
      }
    public Word getNext()
      {
        return next;
      }


}

بس باقي method to string

and

search by pattern

#5
vector_ever كتب:

هل بشترط الحل بواسطة singly linked list ؟؟

نعم

#6

جربت دا الكود طلع غلط

 public void SearchWithPattren(){
   String w = null ;
   System.out.println("pleas inter the first latter of the word ");
   w = scan1.nextLine();
   int count = 0 ;
   while (Head.getWord().equals(w)){
   System.out.println(Head.getWord()+Head.getMeaning());
#7

لو سمحتوا احتاج المساعده ضروري

#8

السلام عليكم ..

هل هذا هو المطلوب ..

package myPackage;

public class Test
{
	public static void main(String[] args)
	{
    	String hello = "hello";

    	if(hello.startsWith("hel"))
        	System.out.println("hello startsWith hel");
    	if(hello.lastIndexOf("ll") > 0)
        	System.out.println("hello contains ll");


	}

}

لا إله إلا الله ... محمد رسول الله

لو كانت مشاركتي مفيدة و تريد تشجيعي على المزيد من العطاء , فضلا قم بتقييم المشاركة

المعرًف القديم : houssam11350_11350

من مواضيعي : ArabGenCode : مولد كود و إجراءات مخزنة و واجهات لجداول سيكوال سيرفر

#9
houssam11350_11350 كتب:

السلام عليكم ..

هل هذا هو المطلوب ..

package myPackage;

public class Test
{
	public static void main(String[] args)
	{
    	String hello = "hello";

    	if(hello.startsWith("hel"))
        	System.out.println("hello startsWith hel");
    	if(hello.lastIndexOf("ll") > 0)
        	System.out.println("hello contains ll");


	}

}

تقريبا

انا ابغا امر على كل ك اللينك ليست واشيك اذا في كلمة تبدا بالحرف اللي ادخله اليوزر يطبعله كل الكلمات اللي تبدا بنفس الحرف ومعانيها

حاولت اني ازبط الميثود بس يطلعلي غلط

 public void SearchWithPattren(){
   Head=Search ;
   String w ;
   System.out.println("pleas inter the first latter of the word ");
   w = scan1.nextLine();
  if (Search.getWord.startsWith(w))
{
   System.out.println(Search.getWord()+Search.getMeaning());
      }
   }
#10

السلام عليكم ..

if (Search.getWord().startsWith(w))

أنت نسيت الأقواس ...

ما هي رسالة الخطأ ...

لا إله إلا الله ... محمد رسول الله

لو كانت مشاركتي مفيدة و تريد تشجيعي على المزيد من العطاء , فضلا قم بتقييم المشاركة

المعرًف القديم : houssam11350_11350

من مواضيعي : ArabGenCode : مولد كود و إجراءات مخزنة و واجهات لجداول سيكوال سيرفر

#11
houssam11350_11350 كتب:

السلام عليكم ..

if (Search.getWord().startsWith(w))

أنت نسيت الأقواس ...

ما هي رسالة الخطأ ...

وعليكم السلام

اضفت الاقواس وراح الخطا

بس في الرن يطلعلي error في دا الجمله

 if (Search.getWord().startsWith(w))
#12

السلام عليكم ....

هناك أخطاء كثيرة .. منطقية .. (الموضوع شكله حل واجب ..) و لكن لا بأس ...

و هذه بعض الإصلاحات ...

الملف Word.java يبقى كما هو .

الملف Dictionary.Java يصبح :

package myPackage;

import java.util.Scanner;//program uses Scanner
public class Dictionary
{

	Word call = new Word();
	Word Head, Tail, temp, a, prev, current, previos;
	Scanner scan1 = new Scanner(System.in);

//*************************************  All Methods  **************************
	public void Dictionary()
	{
    	Head = null;
    	Tail = null;
	}
	int count;
//*******************************  inseart element at last ********************

	void AddFirst()
	{

    	Word newNode = new Word();

    	System.out.println("Enter the word you want to enter!");
    	newNode.setWord(scan1.nextLine());

    	System.out.println("Enter the Meaning !");
    	newNode.setMeaning(scan1.nextLine());

    	newNode.setNext(Head);
    	if (Head == null)
    	{
        	Tail = newNode;
    	}

    	Head = newNode;
    	count++;
	}
//*******************************  remove from all cases ********************

	public void DeleteANode()    	//<-- i thought it  was funny :)
	{
    	System.out.println("Enter the word you want to delete ");  // faaaaaaaaalse
    	// Word newNode =new Word();
    	String DeleteW = scan1.nextLine();
    	// while(getWord().equalsIgnoreCase(DeleteW))
    	temp = Head;
    	//while(Head.getWord().equalsIgnoreCase(DeleteW))

    	if (Head == null)
    	{
        	System.out.println("error the list is empty");
    	} else
    	{ //search
        	while (temp.getWord().equals(DeleteW))
        	{
            	if (Head.getNext() == null)
            	{
                	Head = null;
            	} else
            	{
                	if ((Head.getNext() != null) && (Head.getNext() != Tail))
                	{
                    	String y = Head.getWord();
                    	Head = Head.getNext();       	//****
                	} else
                	{
                    	if (temp.getNext() != null)
                    	{
                       	// temp.setPrevious(null);
                    	}

                    	Head = prev;
                    	while (prev.getNext() != temp)
                    	{
                        	prev = prev.getNext();
                    	}

                    	if (prev.getNext().getWord().equals(DeleteW))
                    	{
                        	prev.setNext(temp.getNext());
                    	}
                	}
            	}
        	}
    	}
	}

//---------------------------------- Search Meaning ---------------------------
	void SearchForMeaning()
	{
    	System.out.println("Enter the you want to delet "); 	// true
    	String Search = scan1.nextLine();
    	if (Head == null)
    	{
        	System.out.println("error the list is empty");
    	}
    	Word currentNode = Head;

    	while (currentNode.getMeaning().equalsIgnoreCase(Search))
    	{
        	if (currentNode.getNext() != null)
        	{
            	currentNode = currentNode.getNext();
            	System.out.println(currentNode.getMeaning());
        	} else
        	{
            	System.out.println("Didn't find the word");
        	}
    	}
	}
	//----------------------------------Search By pattren ----------------------

	public void SearchWithPattren()
	{
    	System.out.println("pleas inter the first latter of the word ");
    	String w = scan1.nextLine();

    	Word Node = Head;
    	while (Node != null)
    	{
        	if (Node.getWord().startsWith(w))
        	{
            	System.out.println(Node.getWord() + Node.getMeaning() + "\n");
        	}

        	Node = Node.getNext();
    	}
	}

//----------------------------------Display Word-------------------------------
  public   void display()
	{
    	System.out.println("the list is(first-->last:");
    	Word Node = Head;
    	while (Node != null)                       	// faaaaaaaaalse
    	{
        	System.out.println(Node.getWord() + Node.getMeaning() + "\n");
        	Node = Node.getNext();
    	}
	}

	public String toString()
	{

    	//return (getWord() + getMeaning() + "\n");
    	return "MyDictionary";

	}
}//end of class Dictionary

و الملف DictionaryTest.java :

package myPackage;

import java.util.Scanner;

public class TestDictionary
{

	public static void main(String[] args)
	{
    	Dictionary myDictionary = new Dictionary();

    	Scanner scan = new Scanner(System.in);

    	while (true)
    	{
        	System.out.println("***********Quran Word E-Dictionary  ***********");
        	System.out.println("1-insert (add) new word");
        	System.out.println("2-Delete the word");
        	System.out.println("3-Search for meaning ");
        	System.out.println("4-Search with pattren ");
        	System.out.println("5-Displaying all words");
        	System.out.println("6-Exit");
        	System.out.println("\n*Enter you chois ?");

        	int chois = scan.nextInt();
        	switch (chois)
        	{
            	case 1:
            	{
                	myDictionary.AddFirst();
            	}
            	break;
            	case 2:
            	{
                	myDictionary.DeleteANode();
            	}
            	break;
            	case 3:
            	{
                	myDictionary.SearchForMeaning();
            	}
            	break;
            	case 4:
            	{
                	//ShowAllBooks(array,limit);
                	myDictionary.SearchWithPattren();

            	}
            	break;
            	case 5:
            	{
                	myDictionary.display();
            	}
            	break;
            	case 6:
            	{

                	System.exit(0);
            	}
            	break;
            	default:
                	System.out.println("XXXXXXX Rong chois XXXXXX");
                	break;
        	}
        	System.out.println("do you want to choose from the menu again? enter Y for yes,or N for no");
    	}
	}//end of main
}

ملاحظة :

هذه العبارة لم تعمل :

 if (temp.getNext() != null)
                    	{
                       	// temp.setPrevious(null);
                    	}
1

لا إله إلا الله ... محمد رسول الله

لو كانت مشاركتي مفيدة و تريد تشجيعي على المزيد من العطاء , فضلا قم بتقييم المشاركة

المعرًف القديم : houssam11350_11350

من مواضيعي : ArabGenCode : مولد كود و إجراءات مخزنة و واجهات لجداول سيكوال سيرفر

#13

هذا كودي بعد التصحيح واضفت عليها ميوثد ال pattern اللي عدلتها في الرن يطبعلي كل الlist

تم تعديل هذه المشاركة بواسطة همـــس الليل في 1 نوفمبر 2011 في 23:51

#14

الحمدلله زبط الكود

نسيت اضيف الbreak بعد case 4

جزاك الله الف خير

واله يكثر من امثالك

#15

يا ريت تضعي الكود بعد تصحيحه للاستفادة

إذا نظــرتَ نيـوب اللـّيـثِ بـارزةً         فـلا تظــنَنَ أَنَّ اللـّيـــثَ يبْتسـِـــمُ


 


 


رسم المخططات البيانية بواسطة الجافا


 


كتاب تحليل وتصميم نظم المعلومات


#16

ok

import java.util.Scanner;   //program uses Scanner
public class Dictionary {

    public static void main(String[] args) {
        Dictionary call = new Dictionary();
    Scanner scan = new Scanner(System.in);
  int  answer = 1;

     do {
    System.out.println("********* Quran Word E-Dictionary  *********");
    System.out.println("\t1-insert (add) new word");
    System.out.println("\t2-Delete the word");
    System.out.println("\t3-Search for meaning ");
    System.out.println("\t4-Search with pattren ");
    System.out.println("\t5-Displaying all words");
    System.out.println("\t6-Exit");
    System.out.println("\n*Enter you chois ?");

    int chois = scan.nextInt();
    switch (chois) {
        case 1:{
                 call.AddFirst();
        }
        break;
        case 2:{
                 call.DeleteANode() ;
        }
        break;
        case 3:{
                 call.SearchForMeaning ();
        }break;
        case 4:{
                 call.SearchWithPattren();

        }break;
        case 5:{
                 call.ShawAllWords();
        }break;
        case 6:{

        }break;
         default:    System.out.println("XXXXXXX Rong chois XXXXXX");

            }
    System.out.println("Do you want to choose from the menu again?\n Enter 1 if you want to");
    answer =scan.nextInt();
    } while(answer == 1);
    }//end of main
//--------------------------------- All Methods -------------------------------
Word Head,Tail,temp,a,prev,Search;
 Scanner scan1 = new Scanner(System.in);
public void Dictionary (){
    Head = null;
    Tail=null;
}
//------------------------------- inseart element at last ---------------------
     public void AddFirst(){

    Word newNode = new Word ();

    System.out.println("Enter the word you want to enter!");
   newNode.setWord(scan1.nextLine());

        System.out.println("Enter the meaning of the word!");
   newNode.setMeaning(scan1.nextLine());

   newNode.setNext(Head);
   if(Head==null)
   Tail=newNode;

   Head=newNode;
}
//------------------------------ remove from all cases ------------------------

  public void DeleteANode()       //<-- i thought it  was funny :)
        {
        System.out.println("Enter the word you want to delete ");  // faaaaaaaaalse
        // Word newNode =new Word();
        String DeleteW = scan1.nextLine();
        // while(getWord().equalsIgnoreCase(DeleteW))
        temp = Head;
        //while(Head.getWord().equalsIgnoreCase(DeleteW))

        if (Head == null)
        {
                System.out.println("error the list is empty");
        } else
        { //search
                while (temp.getWord().equals(DeleteW))
                {
                if (Head.getNext() == null)
                {
                        Head = null;
                } else
                {
                        if ((Head.getNext() != null) && (Head.getNext() != Tail))
                        {
                        String y = Head.getWord();
                        Head = Head.getNext();          //****
                        } else
                        {
                        if (temp.getNext() != null)
                        {
                        // temp.setPrevious(null);
                        }

                        Head = prev;
                        while (prev.getNext() != temp)
                        {
                                prev = prev.getNext();
                        }

                        if (prev.getNext().getWord().equals(DeleteW))
                        {
                                prev.setNext(temp.getNext());
                        }
                        }
                }
                }
        }
        }

//---------------------------------- Search Meaning ---------------------------
    void SearchForMeaning()
        {
        System.out.println("Enter the you want to delet ");     // true
        String search = scan1.nextLine();
        if (Head == null)
        {
                System.out.println("error the list is empty");
        }
        Word currentNode = Head;

        while (currentNode.getMeaning().equalsIgnoreCase(search))
        {
                if (currentNode.getNext() != null)
                {
                currentNode = currentNode.getNext();
                System.out.println(currentNode.getMeaning());
                } else
                {
                System.out.println("Didn't find the word");
                }
        }
        }



//--------------------------------- Search By pattren -------------------------
       public void SearchWithPattren(){


        System.out.println("pleas inter the first latter of the word ");
        String w = scan1.nextLine();

        Word Node = Head;
        while (Node != null)
        {
             if (Node.getWord().startsWith(w))
             {
              System.out.println(Node.getWord() + Node.getMeaning() + "\n");
              }

               Node = Node.getNext();
        }}

//--------------------------------- Shaw All Words ----------------------------
 public void ShawAllWords(){
    System.out.println("the list is(first-->last:");
    a =Head;
    while(a!=null)                // For printing all list node togather
    {
        System.out.println(a.getWord()+ a.getMeaning());
        a=a.getNext();
    }
    }

}//end of class Dictionary

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