| | |
structure
![]() |
•
•
Join Date: Oct 2006
Posts: 34
Reputation:
Solved Threads: 1
Hi,
I am going to write an exam I found a model question.
could u pls solve this question.
An array named 'DATE_ARRAY' with n elements present in the memory.
Each element in the array is a structure representing the 'Date' information and its type defination is shown below.
Type def struct DATE_st
{
int MM;
int DD;
int YYYY;
}Date;
Assume that the elements in the DATE_ARRAY are sorted in the ascending order for example{date1(3,21,1975)<date(3,22,1975)}.
Write a c program that takes a date as its command line arguement(in the form of numeric string "MMDDYYYY")and use the binary search algorithm to determine wether the input date exists DARE_ARRAY are not.
Could u pls write a c progra for this and wt s the theory behind it.
Thanks & Regards.
I am going to write an exam I found a model question.
could u pls solve this question.
An array named 'DATE_ARRAY' with n elements present in the memory.
Each element in the array is a structure representing the 'Date' information and its type defination is shown below.
Type def struct DATE_st
{
int MM;
int DD;
int YYYY;
}Date;
Assume that the elements in the DATE_ARRAY are sorted in the ascending order for example{date1(3,21,1975)<date(3,22,1975)}.
Write a c program that takes a date as its command line arguement(in the form of numeric string "MMDDYYYY")and use the binary search algorithm to determine wether the input date exists DARE_ARRAY are not.
Could u pls write a c progra for this and wt s the theory behind it.
Thanks & Regards.
•
•
Join Date: Jul 2005
Posts: 1,681
Reputation:
Solved Threads: 264
Here's a rough algorhythm, based on my understanding of the problem as stated and what is done in a binary search of an array of sorted items, that may or may not be useful.
1) Break the input string into three separate substrings representing day string, month string and year string, and then convert those strings into ints that are data members of a holding date structure.
2) Write a function that compares two dates for equality.
3) Write a function that compares two dates for less than.
4) Determine size of DATE_ARRAY and thereby the index of the last element of DATE_ARRAY
5) Determine that holding date not equal to first and last element of DATE_ARRAY
6) Determine the index of the element that is half way between the first and the last element of the array.
7) Let the index b be the beginning of the array, the index m be the midpoint of the array, and the index e be the end of the array.
8) Determine if the holding date is the same, less than, or greater than m. If it's the same as m, then the holding date, which is the passed in date, exists in the array. If it's less than m then let m be e, redetermine the new m between b and e and repeat. If it's not m, and it's not less than m, then it must be greater than m so let m be b and redetermine the new m between b and e and repeat. Continue until you have completed the comparisons or found the date. If b == m == e or e == b + 1 and holding date not equal b or e, then the holding date is not in DATE_ARRAY.
Good luck on writing your program.
1) Break the input string into three separate substrings representing day string, month string and year string, and then convert those strings into ints that are data members of a holding date structure.
2) Write a function that compares two dates for equality.
3) Write a function that compares two dates for less than.
4) Determine size of DATE_ARRAY and thereby the index of the last element of DATE_ARRAY
5) Determine that holding date not equal to first and last element of DATE_ARRAY
6) Determine the index of the element that is half way between the first and the last element of the array.
7) Let the index b be the beginning of the array, the index m be the midpoint of the array, and the index e be the end of the array.
8) Determine if the holding date is the same, less than, or greater than m. If it's the same as m, then the holding date, which is the passed in date, exists in the array. If it's less than m then let m be e, redetermine the new m between b and e and repeat. If it's not m, and it's not less than m, then it must be greater than m so let m be b and redetermine the new m between b and e and repeat. Continue until you have completed the comparisons or found the date. If b == m == e or e == b + 1 and holding date not equal b or e, then the holding date is not in DATE_ARRAY.
Good luck on writing your program.
Last edited by Lerner; Nov 3rd, 2006 at 12:32 pm.
Someone has already provided you with a rough outline of the program as a starting point.
Perhaps you missed this on your way in..? http://www.daniweb.com/techtalkforum...cement8-2.html
Perhaps you missed this on your way in..? http://www.daniweb.com/techtalkforum...cement8-2.html
¿umop apisdn upside down? ![]() |
Similar Threads
- Discrete Math or Data structure (Computer Science)
- Can array works within Structure? (C)
- Structure Help Please (C++)
- Question regarding correct table structure (HTML and CSS)
- Scandisc stops at "File Structure" (Windows 95 / 98 / Me)
Other Threads in the C Forum
- Previous Thread: How to print an equation in order of precedence of operators
- Next Thread: Base conversion
| Thread Tools | Search this Thread |
* ansi api array arrays bash binarysearch calculate centimeter changingto char character convert copyanyfile copypdffile creafecopyofanytypeoffileinc createcopyoffile createprocess() database dynamic execv fflush fgets file floatingpointvalidation fork forloop frequency function getlogicaldrivestrin givemetehcodez grade graphics gtkwinlinux histogram homework i/o ide inches include infiniteloop initialization input interest intmain() iso keyboard km license linked linkedlist linux list looping loopinsideloop. lowest matrix microsoft mysql oddnumber open opendocumentformat openwebfoundation pdf pointer pointers posix power program programming pyramidusingturboccodes radix read recursion recv recvblocked reversing scanf scheduling segmentationfault send sequential shape single socketprogramming stack standard strchr string suggestions test threads turboc unix urboc user variable whythiscodecausesegmentationfault win32api windowsapi






