|
|
| Author |
Message |
cooolguyin Warnings : 1 New User
Joined: 12 May 2005 Posts: 13 Location: chennai
|
|
|
|
here is the interview Q i faced in cts
There are two files one with the records in sorted order , no duplicates and other with unsorted order with duplicates..I want the third file which should contain the records that are in both the first and second file but no duplicates.. should not use merge or sort verb!!.
could you just tell me the logic of this pgm?
Thanks in advance |
|
| Back to top |
|
 |
References
|
Posted: Thu Jun 09, 2005 12:14 am Post subject: Re: cts interview question |
 |
|
|
 |
cooolguyin Warnings : 1 New User
Joined: 12 May 2005 Posts: 13 Location: chennai
|
|
|
|
| and the output file should be in the sorted order! |
|
| Back to top |
|
 |
naive
New User
Joined: 26 Apr 2005 Posts: 47 Location: LA
|
|
|
|
Algo:
1.Read 1st file
2.If not EOF , goto next line ELSE goto line 8.
3. Read 2nd file
3.If 2nd file not EOF, goto next line, ELSE goto 6.
4.If 1st file rec = 2nd file rec, goto next line,ELSE goto line 3.
5.Write record to 3rd file.
6.Close 2nd file,open 2nd file (reset file pointer to 1st record in file 2)
7.Goto 1.
8.END
Assumption:1st file is the sorted one,without duplicates. 2nd file has duplicates and is unsorted.
Lemme know if this is OK. |
|
| Back to top |
|
 |
Santoshhn
New User
Joined: 18 May 2005 Posts: 6
|
|
|
|
Code this logic..this has to work..
if key-1 < key-2 and
key-1 not= hold-key-1
move key-1 to hold-key-1
write record-1
read file-1
else if key-1 > key-2 and
key-2 not= hold-key-2
write record-2
move key-2 to hold-key-2
read file-2
else if key-1 = key-2 and
key-1 not= hold-key-1
write either record-1 or record-2
read file-1
read file-2 |
|
| Back to top |
|
 |
|
|