944,096 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 1567
  • C RSS
Nov 3rd, 2006
0

structure

Expand Post »
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.
Similar Threads
Reputation Points: 12
Solved Threads: 1
Light Poster
pointers is offline Offline
34 posts
since Oct 2006
Nov 3rd, 2006
0

Re: structure

No
Reputation Points: 251
Solved Threads: 29
Posting Whiz in Training
andor is offline Offline
274 posts
since Jun 2005
Nov 3rd, 2006
0

Re: structure

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.
Last edited by Lerner; Nov 3rd, 2006 at 12:32 pm.
Reputation Points: 718
Solved Threads: 373
Nearly a Posting Maven
Lerner is offline Offline
2,253 posts
since Jul 2005
Nov 3rd, 2006
0

Re: structure

>>Could u pls write a c progra for this

Ok, wrote it in about 30 minutes, but I'm not going to post my solution until you post yours (that works)
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is online now Online
21,960 posts
since Aug 2005
Nov 4th, 2006
0

Re: structure

I hav no idea fnd.....pls share u r views.........
Reputation Points: 12
Solved Threads: 1
Light Poster
pointers is offline Offline
34 posts
since Oct 2006
Nov 4th, 2006
0

Re: structure

Click to Expand / Collapse  Quote originally posted by pointers ...
I hav no idea fnd.....pls share u r views.........
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
Reputation Points: 307
Solved Threads: 62
Posting Pro
Bench is offline Offline
565 posts
since Feb 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: How to print an equation in order of precedence of operators
Next Thread in C Forum Timeline: Base conversion





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC