473,398 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Smart Slicing Routine!!

Hi All, I need some smart way to accomplish this task in C# (.net 1.0)

Appreciate your inputs!!
==================================
Input ArrayList:
2,3,4,20
1,2,2
2
2,2,2
1,2,3,4
1,1
null

expected oututs:
Bundle Count=1 and the bundle will contain 2,3,4,20
Bundle Count=3 Bundle#1 wil contain 1 Bundle#2 will contain 2 and Bundle#3
will cotain 2
Bundle Count=1 Bundle#1 will contain 2
Bundle Count=3 Bundle#1 wil contain 2 Bundle#2 will contain 2 and Bundle#3
will cotain 2
Bundle Count=2 Bundle#1 wil contain 1 Bundle#2 will contain 2 ,3,4
{formatted with,}
Bundle Count =2 Bundle#1 wil contain 1 Bundle#2 will contain 1
Null
............
==================================
Jan 29 '07 #1
6 1229
The answers in the other thread will do what you are after. Though seeing
this it was a poor explanation in your original post. And this one isn't too
clear either. So you have a load of array lists each with data and you want
them to be broken up into new arrays of data? Or do you want them broken up
into individual strings? strings arrays? What?

Anyway this is a guide, you do need to apply some coding skill to match your
exact requirement as no one helping knows the context of all this, so:

1) Loop your input array list
2) Get the value of an array slot and check if it is 2 or 1
3) if 2 or 1 create new array, string array whatever it is you want it as,
store it in the array
4) go to next slot, if it is not a 2 or 1 append to the created array in
step 3.
5) If it is a 2 or 1 store the array created and make a new one, store the
2/1 and repeat.

Now do that for every array list being passed in. That will work. Up to you
to apply it. If you struggle to apply it then try and post your code
attempt.
"Vai2000" <no****@microsoft.comwrote in message
news:ue*************@TK2MSFTNGP06.phx.gbl...
Hi All, I need some smart way to accomplish this task in C# (.net 1.0)

Appreciate your inputs!!
==================================
Input ArrayList:
2,3,4,20
1,2,2
2
2,2,2
1,2,3,4
1,1
null

expected oututs:
Bundle Count=1 and the bundle will contain 2,3,4,20
Bundle Count=3 Bundle#1 wil contain 1 Bundle#2 will contain 2 and Bundle#3
will cotain 2
Bundle Count=1 Bundle#1 will contain 2
Bundle Count=3 Bundle#1 wil contain 2 Bundle#2 will contain 2 and Bundle#3
will cotain 2
Bundle Count=2 Bundle#1 wil contain 1 Bundle#2 will contain 2 ,3,4
{formatted with,}
Bundle Count =2 Bundle#1 wil contain 1 Bundle#2 will contain 1
Null
...........
==================================


Jan 29 '07 #2
I am looking for a smart solution, I have already done it but its not a very
smart solution!!
Answers to your questions:
1. The ArrayList stores strings inside it.....
so what I showed below are contents of the arrayList...

I need tight routine!!!

TIA

"Daniel" <no****@pokercat.co.ukwrote in message
news:%2***************@TK2MSFTNGP06.phx.gbl...
The answers in the other thread will do what you are after. Though seeing
this it was a poor explanation in your original post. And this one isn't
too
clear either. So you have a load of array lists each with data and you
want
them to be broken up into new arrays of data? Or do you want them broken
up
into individual strings? strings arrays? What?

Anyway this is a guide, you do need to apply some coding skill to match
your
exact requirement as no one helping knows the context of all this, so:

1) Loop your input array list
2) Get the value of an array slot and check if it is 2 or 1
3) if 2 or 1 create new array, string array whatever it is you want it as,
store it in the array
4) go to next slot, if it is not a 2 or 1 append to the created array in
step 3.
5) If it is a 2 or 1 store the array created and make a new one, store the
2/1 and repeat.

Now do that for every array list being passed in. That will work. Up to
you
to apply it. If you struggle to apply it then try and post your code
attempt.
"Vai2000" <no****@microsoft.comwrote in message
news:ue*************@TK2MSFTNGP06.phx.gbl...
Hi All, I need some smart way to accomplish this task in C# (.net 1.0)

Appreciate your inputs!!
==================================
Input ArrayList:
2,3,4,20
1,2,2
2
2,2,2
1,2,3,4
1,1
null

expected oututs:
Bundle Count=1 and the bundle will contain 2,3,4,20
Bundle Count=3 Bundle#1 wil contain 1 Bundle#2 will contain 2 and
Bundle#3
will cotain 2
Bundle Count=1 Bundle#1 will contain 2
Bundle Count=3 Bundle#1 wil contain 2 Bundle#2 will contain 2 and
Bundle#3
will cotain 2
Bundle Count=2 Bundle#1 wil contain 1 Bundle#2 will contain 2 ,3,4
{formatted with,}
Bundle Count =2 Bundle#1 wil contain 1 Bundle#2 will contain 1
Null
...........
==================================


Jan 29 '07 #3
Hi,

What exactly was not smart about the solution presented in the other
thread?

Brian

On Jan 29, 1:35 pm, "Vai2000" <nos...@microsoft.comwrote:
I am looking for a smart solution, I have already done it but its not a very
smart solution!!
Answers to your questions:
1. The ArrayList stores strings inside it.....
so what I showed below are contents of the arrayList...

I need tight routine!!!

TIA
Jan 29 '07 #4
Sadly No! Dont worry about it...I finally wrote it myself
===================================

for(int idx=0;idx<alNonBundle.Count;idx++)
{
str=alNonBundle[idx];

if(str.Equals("2") || str.Equals("1"))
{
pos=idx;

CopyArray(lastpos,pos,alNonBundle);

lastpos=pos;
}

}
void CopyArray(int spos,int epos,ArrayList al)
{
string []arr=new string[epos-spos];
al.CopyTo(spos,arr,0,epos-spos);
}

"Brian Gideon" <br*********@yahoo.comwrote in message
news:11**********************@l53g2000cwa.googlegr oups.com...
Hi,

What exactly was not smart about the solution presented in the other
thread?

Brian

On Jan 29, 1:35 pm, "Vai2000" <nos...@microsoft.comwrote:
I am looking for a smart solution, I have already done it but its not a
very
smart solution!!
Answers to your questions:
1. The ArrayList stores strings inside it.....
so what I showed below are contents of the arrayList...

I need tight routine!!!

TIA

Jan 29 '07 #5
Hi,

Are you sure that's right? That code doesn't produce any side
effects. Seems like the following is more of what you want.

public IList Partition(IList input)
{
IList output = new ArrayList();
IList bundle = new ArrayList();
foreach (string item in input)
{
if (bundle.Count 0 && (item == "1" || item == "2"))
{
output.Add(bundle);
bundle = new ArrayList();
}
bundle.Add(item);
}
output.Add(bundle);
return output;
}

Brian

On Jan 29, 2:31 pm, "Vai2000" <nos...@microsoft.comwrote:
Sadly No! Dont worry about it...I finally wrote it myself
===================================

for(int idx=0;idx<alNonBundle.Count;idx++)
{
str=alNonBundle[idx];

if(str.Equals("2") || str.Equals("1"))
{
pos=idx;

CopyArray(lastpos,pos,alNonBundle);

lastpos=pos;
}

}void CopyArray(int spos,int epos,ArrayList al)
{
string []arr=new string[epos-spos];
al.CopyTo(spos,arr,0,epos-spos);

}
Jan 29 '07 #6
You actually tried? For yourself! Gasp! Surely not..... Word of advice and
friendly tip. Don't use exclamation marks when asking for help, try not to
be rude about help you are given and be respectful of others.

"Vai2000" <no****@microsoft.comwrote in message
news:%2******************@TK2MSFTNGP03.phx.gbl...
Sadly No! Dont worry about it...I finally wrote it myself
===================================

for(int idx=0;idx<alNonBundle.Count;idx++)
{
str=alNonBundle[idx];

if(str.Equals("2") || str.Equals("1"))
{
pos=idx;

CopyArray(lastpos,pos,alNonBundle);

lastpos=pos;
}

}
void CopyArray(int spos,int epos,ArrayList al)
{
string []arr=new string[epos-spos];
al.CopyTo(spos,arr,0,epos-spos);
}

"Brian Gideon" <br*********@yahoo.comwrote in message
news:11**********************@l53g2000cwa.googlegr oups.com...
>Hi,

What exactly was not smart about the solution presented in the other
thread?

Brian

On Jan 29, 1:35 pm, "Vai2000" <nos...@microsoft.comwrote:
I am looking for a smart solution, I have already done it but its not a
very
smart solution!!
Answers to your questions:
1. The ArrayList stores strings inside it.....
so what I showed below are contents of the arrayList...

I need tight routine!!!

TIA


Jan 29 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

32
by: Dave Benjamin | last post by:
Hey all, I just realized you can very easily implement a sequence grouping function using Python 2.3's fancy slicing support: def group(values, size): return map(None, * for i in...
8
by: Christian Stigen Larsen | last post by:
Consider the following: class parent { public: virtual void print() { printf("Parent\n"); } }; class child : public parent {
6
by: Shankar | last post by:
Hello, We have a smart pointer class which provides the dereference operator -> to access the underlying object pointer. Now, we have a new requirement where a different type of object (e.g from...
3
by: Bryan Olson | last post by:
I recently wrote a module supporting value-shared slicing. I don't know if this functionality already existed somewhere, but I think it's useful enough that other Pythoners might want it, so here...
5
by: Neal Coombes | last post by:
Posted to comp.lang.c++.moderated with little response. Hoping for better from the unmoderated groups: -------- Original Message -------- Subject: Return appropriately by value, (smart)...
11
by: jbperez808 | last post by:
>>> rs='AUGCUAGACGUGGAGUAG' >>> rs='GAG' Traceback (most recent call last): File "<pyshell#119>", line 1, in ? rs='GAG' TypeError: object doesn't support slice assignment You can't assign to...
17
by: baibaichen | last post by:
i have written some code to verify how to disable slicing copy according C++ Gotchas item 30 the follow is my class hierarchy, and note that B is abstract class!! class B { public: explicit...
19
by: AlesD | last post by:
Hello, I have problem that when I use std::list<MyClassand then store various subclasses of MyClass in that list (or any other STL container) the instances get sliced. I have read FAQ: ' What...
6
by: Vai2000 | last post by:
Hi All, I am looking for a smart solution to accomplish this task (.net 1.0) Appreciate your input I have a group of numbers in an arrayList 2,3,5,2,1,2,2 I need to output them into groups of...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.