### Author Topic: creating an array of numbers  (Read 5429 times)

#### muratohyes

• Jr. Member
• Posts: 17
##### creating an array of numbers
« on: July 01, 2014, 11:03:11 AM »
I'm trying to populate an array of "string"s. These include only 1..9 as digits and each digit in a number should be different. The number of digits is taken from the user.
As the digits will be non-zero and different, I wrote some code to determine the starting point and ending point of the numbers. e.g 4 digits start from 1234 to 9876.

My algorithm on solving the issue is like following:

from i =1234 to 9876
if: all the chars are different and non-zero in the current number
s = convert.tostring(i)

So I need a data structure/method like linked list. How should I act in such a situation? Any code or algorithm would be great. I especially need help on allocation of and adding a new element to the list.

#### Frank Kotler

• NASM Developer
• Hero Member
• Posts: 2667
• Country:
##### Re: creating an array of numbers
« Reply #1 on: July 02, 2014, 04:27:04 AM »
Hi Muratohyes,

It isn't clear what you propose to do with this list once you've got it, which might make a difference. Perhaps something like...
Code: [Select]
`struc listnode    .pnext resq 1    .pstr resq 1; .pprev resq 1 :?endstrucsection .bss    listhead resq 1section .text; ...addnode:; ummm parameters listhead and pointer to string?; returns... address of new node? or just success (or not); traverse to current end of list; (listnode + listnode.pnext = 0); move it to... say... rbx?mov rdi, listnode_sizecall malloc ; yours or library?mov [rbx + listnode.pnext], raxmov [rax + listnode.pnext], 0mov [rax + listnode.pstr], rsi ; passed in parameterret ;? are we done?`That obviously isn't intended to run, but "something like that"? If I haven't screwed it up too badly?

You haven't given us much of a clue what we're up against. What OS? What bitness? What parts can you do? Where do you get stuck? The more you give us, the more we can/will give you!

Best,
Frank