473,382 Members | 1,425 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,382 software developers and data experts.

Array push&pop

I would like to move the values of an array up one in the index.
This is what i tried but it didn't work.
int[] intArr = new int[5];
Array.Copy(intArr, 0, intArr 1, 4);
intArr[0] = userinput;

//this is how it should work
userinput: 5
intArr {5,null,null,null,null}

userinput: 4
intArr {4,5,null,null,null}

userinput: 9090
intArr {9090,4,5,null,null}
////

Thanks in advance
Nov 16 '05 #1
2 3387
Not sure what you mean, but the following program appears to work:

using System;

public class ShiftArray {
private static void Main() {
int[] foo = new int[5];
int count = 9;

while(count > 0) {
foo[0] = count--;
DumpContents(foo);

Array.Copy(foo, 0, foo, 1, 4);
}
}

private static void DumpContents(int[] array) {
for(int i = 0; i < array.Length; i++) {
Console.Write(array[i]);
}
Console.WriteLine();
}
}

--
Justin Rogers
DigiTec Web Consultants, LLC.
Blog: http://weblogs.asp.net/justin_rogers

"Aaron" <ku*****@yahoo.com> wrote in message
news:b4*************************@posting.google.co m...
I would like to move the values of an array up one in the index.
This is what i tried but it didn't work.
int[] intArr = new int[5];
Array.Copy(intArr, 0, intArr 1, 4);
intArr[0] = userinput;

//this is how it should work
userinput: 5
intArr {5,null,null,null,null}

userinput: 4
intArr {4,5,null,null,null}

userinput: 9090
intArr {9090,4,5,null,null}
////

Thanks in advance

Nov 16 '05 #2
Aaron wrote:
//this is how it should work
userinput: 5
intArr {5,null,null,null,null}

userinput: 4
intArr {4,5,null,null,null}

userinput: 9090
intArr {9090,4,5,null,null}
////


Have a look at System.Collections.Stack.

--
Gravity: it's not just a good idea, it's the law.
Nov 16 '05 #3

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

Similar topics

7
by: Alex Vinokur | last post by:
========================================== Windows 2000 Professional CYGWIN_NT-5.0 1.5.4(0.94/3/2) GNU g++ version 3.2 20020927 (prerelease) GNU objdump 2.14.90 20030901...
5
by: someone | last post by:
On page 106 of the second edition of "The C Programming Language" by K & G, two stack operations PUSH n POP are given. >> PUSH *p++ = val; >>POP val = *--p; What I know about stacks is...
3
by: Mel | last post by:
i have an text field and a button when user click on button it popups up list of emails in a form user selects a bunch of people from the form (check boxes) and when the window is closed the...
3
by: someone | last post by:
On page 106 of the second edition of "The C Programming Language" by K & G, two stack operations PUSH n POP are given. >> PUSH *p++ = val; >>POP val = *--p; What I know about stacks is...
8
by: G Patel | last post by:
Can people please comment on the layout/style of my problem? The major issue I had was the layout. I ended up having to put a relatively large switch statement, inside an if statement, which is...
2
by: Aaron | last post by:
I would like to move the values of an array up one in the index. This is what i tried but it didn't work. int intArr = new int; Array.Copy(intArr, 0, intArr 1, 4); intArr = userinput; ...
4
by: alisaee | last post by:
plz check what i have made wrong what is requierd her is to creat class queue and class stack and run the push,pop operation . #include<iostream.h> #include<conio.h> #include<stdio.h> class...
14
by: Bryan Parkoff | last post by:
Do you know that current C++ Compiler limits to 64KB segments in source code? It is good news that Microsoft Visual C++ 2005 has expanded to 4GB segments in source code. 4GB segment is ideal for...
11
by: mdh | last post by:
I wonder if I could ask for help. I have been struggling with this most of the day, and cannot understand what is going on. The problems are (1) it does not work!! (but exits normally on...
4
by: matth | last post by:
I've been working on something that deals with handling a user's selection within the DOM and I'm tripping up on one last, but crucial, detail. Forgive me for the length of the code, but my...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.