Topic
• 3 replies
• Latest Post - ‏2012-11-20T11:53:02Z by MohanRS
MohanRS
6 Posts

# Pinned topic unique array determination

‏2012-11-19T18:44:26Z |
Hi friends,

I have an array

string arr[7]={"Apple","orange","orange","pineapple","Apple","Apple","orange"}

i like output to printed

Apple - 3
orange -3
pineapple -1

Updated on 2012-11-20T11:53:02Z at 2012-11-20T11:53:02Z by MohanRS
• llandale
3035 Posts

#### Re: unique array determination

‏2012-11-19T20:02:37Z
//*********************
bool fPutSkipIncrement(Skip skpList, string KeyValue)
{ // Insert the KeyValue into the Skip list's 'Key'.
// The 'Data' portion of the Skip is set to 1 for new inserts and is
// incremented for already existing 'Key's in the Skip.
// 'Data' MUST be of type Integer.
// (represents the number of references).
// Return whether this is a first insert for KeyValue into the Skip.

bool IsNewValue = false

int NumReferences = 0 // Remains zero if next "find" doesn't find anything:
if(find(skpList, KeyValue, NumReferences))
delete(skpList, KeyValue) // Remove It
else IsNewValue = true // Mark it New
// ReInsert new or updated counts
NumReferences++
put (skpList, KeyValue, NumReferences)
return(IsNewValue)
} // end fPutSkipIncrement()

// ========== MAIN =============
string arr[7]={"Apple","orange","orange","pineapple","Apple","Apple","orange"}

int i, Count
string Fruit
Skip skpTotals = createString() // KEY 'string' fruit; DATA 'int' count

for (i=0; i<sizeof(arr); i++)
{ fPutSkipIncrement(skpTotals, arr[i])
}
for Count in skpTotals do
{ Fruit = (string key skpTotals)
print Count "\t" Fruit "\n"
}
delete(skpTotals)
• llandale
3035 Posts

#### Re: unique array determination

‏2012-11-19T20:03:32Z
• llandale
• ‏2012-11-19T20:02:37Z
//*********************
bool fPutSkipIncrement(Skip skpList, string KeyValue)
{ // Insert the KeyValue into the Skip list's 'Key'.
// The 'Data' portion of the Skip is set to 1 for new inserts and is
// incremented for already existing 'Key's in the Skip.
// 'Data' MUST be of type Integer.
// (represents the number of references).
// Return whether this is a first insert for KeyValue into the Skip.

bool IsNewValue = false

int NumReferences = 0 // Remains zero if next "find" doesn't find anything:
if(find(skpList, KeyValue, NumReferences))
delete(skpList, KeyValue) // Remove It
else IsNewValue = true // Mark it New
// ReInsert new or updated counts
NumReferences++
put (skpList, KeyValue, NumReferences)
return(IsNewValue)
} // end fPutSkipIncrement()

// ========== MAIN =============
string arr[7]={"Apple","orange","orange","pineapple","Apple","Apple","orange"}

int i, Count
string Fruit
Skip skpTotals = createString() // KEY 'string' fruit; DATA 'int' count

for (i=0; i<sizeof(arr); i++)
{ fPutSkipIncrement(skpTotals, arr[i])
}
for Count in skpTotals do
{ Fruit = (string key skpTotals)
print Count "\t" Fruit "\n"
}
delete(skpTotals)

Oops

```//*********************
bool    fPutSkipIncrement(Skip skpList, string KeyValue)
{     // Insert the KeyValue into the Skip list's 'Key'.
// The 'Data' portion of the Skip is set to 1 for new inserts and is
//    incremented for already existing 'Key's in the Skip.
// 'Data' MUST be of type Integer.
//   (represents the number of references).
// Return whether this is a first insert for KeyValue into the Skip.

bool    IsNewValue = false

int     NumReferences = 0       // Remains zero if next "find" doesn't find anything:
if(find(skpList, KeyValue, NumReferences))
delete(skpList, KeyValue)          // Remove It
else IsNewValue = true                  // Mark it New
// ReInsert new or updated counts
NumReferences++
put (skpList, KeyValue, NumReferences)
return(IsNewValue)
}     // end fPutSkipIncrement()

string arr[7]={"Apple","orange","orange","pineapple","Apple","Apple","orange"}

int     i, Count
string  Fruit
Skip    skpTotals = createString() // KEY 'string' fruit; DATA 'int' count

for (i=0; i<sizeof(arr); i++)
{  fPutSkipIncrement(skpTotals, arr[i])
}
for Count in skpTotals do
{  Fruit = (string key skpTotals)
print Count "\t" Fruit "\n"
}
delete(skpTotals)
```
Updated on 2014-01-09T10:34:20Z at 2014-01-09T10:34:20Z by iron-man
• MohanRS
6 Posts

#### Re: unique array determination

‏2012-11-20T11:53:02Z
• llandale
• ‏2012-11-19T20:03:32Z

Oops

<pre class="javascript dw" data-editor-lang="js" data-pbcklang="javascript" dir="ltr">//********************* bool fPutSkipIncrement(Skip skpList, string KeyValue) { // Insert the KeyValue into the Skip list's 'Key'. // The 'Data' portion of the Skip is set to 1 for new inserts and is // incremented for already existing 'Key's in the Skip. // 'Data' MUST be of type Integer. // (represents the number of references). // Return whether this is a first insert for KeyValue into the Skip. bool IsNewValue = false int NumReferences = 0 // Remains zero if next "find" doesn't find anything: if(find(skpList, KeyValue, NumReferences)) delete(skpList, KeyValue) // Remove It else IsNewValue = true // Mark it New // ReInsert new or updated counts NumReferences++ put (skpList, KeyValue, NumReferences) return(IsNewValue) } // end fPutSkipIncrement() string arr[7]={"Apple","orange","orange","pineapple","Apple","Apple","orange"} int i, Count string Fruit Skip skpTotals = createString() // KEY 'string' fruit; DATA 'int' count for (i=0; i<sizeof(arr); i++) { fPutSkipIncrement(skpTotals, arr[i]) } for Count in skpTotals do { Fruit = (string key skpTotals) print Count "\t" Fruit "\n" } delete(skpTotals) </pre>
It Works!!! Thanks llandale