adi

Sun 17 Feb 2008 01:08:25
Sun 17 Feb 2008 01:08:25
You can calculate the time required to execute certain line/block of your code by including the header file time.h naka. So you can try something like this in C or C++
#include stdio.h // There should be angular brackets around the header files, but the headers
#include time.h // don't show when I did that, so I just put the header files here without them
int main ()
{
time_t start2D, end2D; // Declare your time variables
time_t start3D, end3D;
double diff2D; // Declare time different variables
double diff3D;
int twoDArray[ ][ ]; // Declare arrays of int (can be char too) of desire size
int threeDArray[ ][ ][ ]; // (need to put integers in the square brackets)
// Calculate time for searching a specific position in 2D
time (&start2D);
twoDArray[ ][ ]; // again need to put integers in the square brackets
time (&end2D);// Do the same for threeDArray
// Calculate the time spent
diff2D = difftime (end2D,start2D);
diff3D = difftime (end3D,start3D);
// Print values out
printf ("It took %.2lf seconds to search in 2D array.\n", diff2D );
printf ("It took %.2lf seconds to search in 3D array.\n", diff3D );
return 0;
}
ช่วยแก้ code ภาษา C หน่อยค่ะ
เกี่ยวกับการเปรียบเทียบเวลาระหว่าง Array 2 มิติ กับ array3 มิติ ไม่รู้ว่า error แก้ยังไง
#include stdio.h // There should be angular brackets around the header files, but the headers
#include time.h // don't show when I did that, so I just put the header files here without them
int main ()
{
time_t start2D, end2D; // Declare your time variables
time_t start3D, end3D;
double diff2D; // Declare time different variables
double diff3D;
int twoDArray[ ][ ]; // Declare arrays of int (can be char too) of desire size
int threeDArray[ ][ ][ ]; // (need to put integers in the square brackets)
// Calculate time for searching a specific position in 2D
time (&start2D);
twoDArray[ ][ ]; // again need to put integers in the square brackets
time (&end2D);// Do the same for threeDArray
// Calculate the time spent
diff2D = difftime (end2D,start2D);
diff3D = difftime (end3D,start3D);
// Print values out
printf ("It took %.2lf seconds to search in 2D array.\n", diff2D );
printf ("It took %.2lf seconds to search in 3D array.\n", diff3D );
return 0;
}
ช่วยแก้ code ภาษา C หน่อยค่ะ
เกี่ยวกับการเปรียบเทียบเวลาระหว่าง Array 2 มิติ กับ array3 มิติ ไม่รู้ว่า error แก้ยังไง
webmaster

Sun 17 Feb 2008 14:07:51
Sun 17 Feb 2008 14:07:51
ถ้าเอาโค๊ดของคนอื่นมาอ่านคำแนะนำของเขาด้วยครับ โค๊ดข้างบนนี้ยังไม่ครบนี่ครับ
adi

Sun 17 Feb 2008 23:07:26
Sun 17 Feb 2008 23:07:26
ให้ code มาแล้วงง พอจะแก้ตรงไหนได้บ้าง ช่วยแนะนำหน่อยค่ะ
webmaster

Sun 17 Feb 2008 23:18:46
Sun 17 Feb 2008 23:18:46
ขอแนะนำให้อ่านหนังสือเพิ่มครับ ถ้าบอกมากกว่านี้คงต้องเขียนโค๊ดให้ ซึ่งทำให้ไม่ได้ครับ

















