배열의중간에있는 한요소를 제거하고싶을때

jjjjrr의 이미지

안녕하세요

WSAEVENT m_EventArray[60];

위와같은배열이 있을때

중간에있는 한요소를 제거하고싶을때 어떻게하는지 부탁합니다

그러니까

위배열에서 인덱스가 25 인요소를 제거하고싶읍니다

인덱스가 25인요소를 지우고 인덱스가 26 이 25자리로 27이 26자리로

한칸식 당겨오게만들어야됩니다

특정인덱스를제거한다는것이 제거하고 제거된자리를 그 이후에있는 요소들이

한칸식 당겨와야됩니다

memcpy, CopyMemory.....

이런함수이용하면된다는데 잘모르겠읍니다

조언부탁드립니다

새해복많이들 받으세요

버려진의 이미지

저번에 보니 구조체도 그냥 = 가 된다더군요. (그런줄도 모르고 매번 클래스를 부러워했는데 ㅠㅠ)

순서가 중요한게 아니라면 하나씩 당길 필요 없이, 제일 마지막걸 지울 위치에 복사하고, 마지막것만 없애면 되겠죠?

SoftOn의 이미지

  memcpy(&m_EventArray[25], &m_EventArray[26], (60-26)*sizeof(m_EventArray[0]));
  memset(&m_EventArray[59], 0, sizeof(m_EventArray[0]));

배열 25번 자리가 빠지게 만들었습니다.
마지막 것은 0으로 메모리를 초기화했습니다.

doldori의 이미지

SoftOn wrote:
  memcpy(&m_EventArray[25], &m_EventArray[26], (60-26)*sizeof(m_EventArray[0]));
  memset(&m_EventArray[59], 0, sizeof(m_EventArray[0]));


원본 영역과 복사될 영역이 겹칠 때는 memcpy를 쓰면 안되고 memmove를
써야 합니다.
zienie의 이미지

촙5 wrote:

순서가 중요한게 아니라면 하나씩 당길 필요 없이, 제일 마지막걸 지울 위치에 복사하고, 마지막것만 없애면 되겠죠?

순서가 상관 없다면
가장 빠르겠군요 ^^

##########################################################
넘어지는건 아직 괜찮다.
하지만 넘어질때마다 무언가를 주워서 일어나자.

cinsk의 이미지

array element 하나를 제거하기 위해 모든 배열의 값을 이동시키는 것은 별로 좋은 방법이 아닙니다. 배열이 커질 수록 시간만 많이 잡아먹기 때문이죠. 물론 항상 깔끔하게 해결하기는 힘듭니다만, 첫째 대개의 경우 특정 값을 magic value로 설정하고 (예를 들어 -1) 이 magic value가 발견되면, 이 element는 빈 것으로 처리한다거나, 둘째, 따로 index array를 두어 indirect indexing을 한다거나, 세째, insert/delete가 자주 일어난다면 array 대신 linked list를 써서 해결하는 방법도 있습니다.

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.