Sod 2 public static int SodStackintDS int source0
. ﻭﺍﻛﺘﺐ ﻣﺎﺫﺍ ﻳﻜﻮﻥ ﺍﻟﻤﺨﺮﺝ , ﺑﺎﻟﻨﺴﺒﺔ ﻟﻠﻤﻌﻄﻴﺎﺕ ﺑﻘﺴﻢ ﺍ ﻭ ﺑﻘﺴﻢ ﺏ Sod ( ﺗﺘﺒﻊ ﺑﻮﺍﺳﻄﺔ ﺟﺪﻭﻝ ﻣﺘﺎﺑﻌﺔ ﺍﻟﻌﻤﻠﻴﺔ 2 public static int Sod(Stack<int>[]DS) { int source=0, target=1, x; while(!DS[source]. is. Empty()) { x=DS[source]. pop(); Spoil(DS[source], DS[target]); source=1 -source; target=1 -target; } if(source==1)return x; else return -1; } ﺏ DS[1] DS[0] ﺍ DS[1] DS[0] 3 4 5 7 7 2 8
public static int Sod(Stack<int>[]DS) { int source=0, target=1, x; while(!DS[source]. is. Empty()) { x=DS[source]. pop(); Spoil(DS[source], DS[target]); source=1 -source; target=1 -target; } if(source==1)return x; else return -1; } 1 2 3 4 source 0 1 target 1 0 ﺏ DS[1] DS[0] 3 5 7 8 while true x 4 Spoil ﺗﻨﻔﻴﺬ true false 2 7 ﺗﻨﻔﻴﺬ ﺍ DS[1] 4 2 7 7 27 if true ﺑﻨﻔﺲ ﺍﻟﻄﺮﻳﻘﺔ ﻧﺤﻞ ﻗﺴﻢ ﺏ . Sod ( ﻣﺎ ﻫﻲ ﺗﻌﻘﻴﺪﺍﺕ ﺍﻟﻌﻤﻠﻴﺔ 1 ﻟﻤﺎﺫﺍ ؟. O(n 2) ﺍﻟﺠﻮﺍﺏ DS[0] ﺍﻟﻌﻤﻠﻴﺔ ﺗﺮﺟﻊ 7
- Slides: 14