954,496 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

structure

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)

pointers
Light Poster
34 posts since Oct 2006
Reputation Points: 12
Solved Threads: 1
 
andor
Posting Whiz in Training
276 posts since Jun 2005
Reputation Points: 251
Solved Threads: 29
 

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.

Lerner
Nearly a Posting Maven
2,382 posts since Jul 2005
Reputation Points: 739
Solved Threads: 396
 

>>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)

Ancient Dragon
Retired & Loving It
Team Colleague
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
 

I hav no idea fnd.....pls share u r views.........

pointers
Light Poster
34 posts since Oct 2006
Reputation Points: 12
Solved Threads: 1
 
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/techtalkforums/announcement8-2.html

Bench
Posting Pro
577 posts since Feb 2006
Reputation Points: 307
Solved Threads: 63
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You