structure

Reply

Join Date: Oct 2006
Posts: 34
Reputation: pointers is an unknown quantity at this point 
Solved Threads: 1
pointers pointers is offline Offline
Light Poster

structure

 
0
  #1
Nov 3rd, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 275
Reputation: andor has a spectacular aura about andor has a spectacular aura about andor has a spectacular aura about 
Solved Threads: 29
andor's Avatar
andor andor is offline Offline
Posting Whiz in Training

Re: structure

 
0
  #2
Nov 3rd, 2006
No
If you want to win, you must not loose (Alan Ford)
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1,681
Reputation: Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all Lerner is a name known to all 
Solved Threads: 264
Lerner Lerner is offline Offline
Posting Virtuoso

Re: structure

 
0
  #3
Nov 3rd, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,407
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1468
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: structure

 
0
  #4
Nov 3rd, 2006
>>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)
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 34
Reputation: pointers is an unknown quantity at this point 
Solved Threads: 1
pointers pointers is offline Offline
Light Poster

Re: structure

 
0
  #5
Nov 4th, 2006
I hav no idea fnd.....pls share u r views.........
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 487
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Solved Threads: 48
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

Re: structure

 
0
  #6
Nov 4th, 2006
Originally Posted by pointers View Post
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
¿umop apisdn upside down?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC