| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 779 人关注过本帖
标题:结构体中怎样定义后继结点(next)
只看楼主 加入收藏
诸葛修勤
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:549
专家分:1955
注 册:2010-10-28
结帖率:96.55%
收藏
已结贴  问题点数:20 回复次数:8 
结构体中怎样定义后继结点(next)
想利用结构体实现树的相关操作 但是不知道这样里来定义结构体的后继
在下面的代码中
程序代码:
;#Mode=CON

.386
.model flat, stdcall
option casemap:none

include Irvine32.inc
include user32.inc
include windows.inc
include kernel32.inc

includelib user32.lib
includelib kernel32.lib
includelib masm32.lib
include macro.asm


node    struct
    Name_    BYTE 20 dup(0)
    Year_    WORD ?
    ;next 
node    ends

.data
xyz    node <>

.code
main    proc
    mov ecx, lengthof xyz.Name_
    mov edx, offset xyz.Name_
    call ReadString
    call Crlf
   
    call WriteString
    call Crlf
   
    call WaitMsg
    invoke ExitProcess, 0
main    endp
end main
怎样定义它的后继结点
例如 c版
struct node
{
    char Name_[20];
    int Year_;
    struct node * next;
};


试过几个(next ptr node <>  next ptr node struct <>)都不行

那位前辈指导下

搜索更多相关主题的帖子: 结构体 
2011-03-16 13:07
zaixuexi
Rank: 12Rank: 12Rank: 12
来 自:上海
等 级:火箭侠
威 望:8
帖 子:858
专家分:3233
注 册:2010-12-1
收藏
得分:20 
试试next ptr struc node <>
收到的鲜花

技术问题,请不要以短消息方式提问
2011-03-16 13:16
诸葛修勤
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:549
专家分:1955
注 册:2010-10-28
收藏
得分:0 
D:\hb\masmplus\Project\CONSOLE.asm(21) : error A2008: syntax error : ptr

几种格式(包括next ptr struc node <>)都是上面的错误信息

2011-03-16 13:29
zaixuexi
Rank: 12Rank: 12Rank: 12
来 自:上海
等 级:火箭侠
威 望:8
帖 子:858
专家分:3233
注 册:2010-12-1
收藏
得分:0 
手头没编译器,晚上帮你试下
收到的鲜花

技术问题,请不要以短消息方式提问
2011-03-16 14:01
zaixuexi
Rank: 12Rank: 12Rank: 12
来 自:上海
等 级:火箭侠
威 望:8
帖 子:858
专家分:3233
注 册:2010-12-1
收藏
得分:0 
没想到什么好的方法,只能这样了
node    struc
    Name_    BYTE 20 dup(0)
    Year_    WORD ?
    next     DWORD ?
node    ends
收到的鲜花

技术问题,请不要以短消息方式提问
2011-03-16 22:06
诸葛修勤
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:549
专家分:1955
注 册:2010-10-28
收藏
得分:0 
程序代码:
;#Mode=CON

.386
.model flat, stdcall
option casemap :none

include Irvine32.inc
include windows.inc
include user32.inc
include kernel32.inc
include masm32.inc

includelib user32.lib
includelib kernel32.lib
includelib masm32.lib
include macro.asm

MultArray proto, x:ptr DWORD, y:ptr DWORD, z:DWORD

node     struct
    Name_    BYTE 20 dup(0)
    Year_    DWORD ?
    Next_    DWORD ?
node    ends

.data
hHeap    DWORD ?
header    DWORD NULL

.code
main    proc
    invoke GetProcessHeap
    .if eax == NULL
        jmp quit
    .else
        mov hHeap, eax
    .endif
   
    invoke HeapAlloc, hHeap, HEAP_ZERO_MEMORY, sizeof node
    .if eax == NULL
        jmp quit
    .else
        mov header, eax
    .endif
   
    mov esi, header
    mov (node ptr [esi]).Year_, 200
    ;mov edx, offset ((node ptr [esi]).Name_)
    lea edx, (node ptr[esi]).Name_
    mov ecx, sizeof node.Name_
    call ReadString
    call WriteString
    call Crlf
    mov (node ptr [esi]).Next, 0
    mov eax, (node ptr [esi]).Year_
    call WriteHex
    call Crlf
   
quit:
    call WaitMsg
    invoke ExitProcess, 0
main    endp
end main
这样可以  谢谢
2011-03-17 19:05
诸葛修勤
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:549
专家分:1955
注 册:2010-10-28
收藏
得分:0 
建立一个单链表
功能:
录入 和 打印出来数据
程序代码:
;#Mode=CON

.386
.model flat, stdcall
option casemap :none

include Irvine32.inc
include windows.inc
include user32.inc
include kernel32.inc
include masm32.inc

includelib user32.lib
includelib kernel32.lib
includelib masm32.lib
include macro.asm


list_node    struct
    data_    DWORD ?
    next_    DWORD ?
list_node    ends
    

.data
count    DWORD ?        ;示链表结点数
hHeap    DWORD ?        ;对分配的句柄
header    DWORD NULL    ;链表的头结点

output_msg    BYTE "输入链表结点的个数: ", 0
input_data    BYTE "输入一个整数: ", 0




.code
main    proc
    ;获取堆的句柄
    call GetProcessHeap
    .if eax == NULL
        call WriteWindowsMsg
        jmp quit
    .elseif
        mov hHeap, eax
    .endif
   
    ;从终端接收一个整数表示链表的结点数
    mov edx, offset output_msg
    call WriteString
    call ReadInt
    mov count, eax
L1:
    invoke HeapAlloc, hHeap, HEAP_ZERO_MEMORY, sizeof list_node   ;这句开始在进行一次分配内存的时候(当然不是现在这个程序)按照这种思路没有问题
                                                                  ;现在不能确定 在多次重复调用的时候会不会出错 或者 说 是允许这样的操作码?
    .if eax == NULL                                               
        call WriteWindowsMsg
        jmp quit
    .elseif
        .if header == NULL
            mov header, eax
            mov (list_node ptr [header]).next_, NULL    ; 对于这样的表示方式(暂时就知道这样子表示)行吗?
        .elseif
            mov ebx, header
            mov (list_node ptr[eax]).next_, ebx
            mov header, eax
        .endif
    .endif
    mov edx, offset input_data
    call WriteString
    call ReadInt
    mov (list_node ptr[header]).data_, eax   
    dec count
    cmp count, 0
    ja L1
   
    mov esi, header            ;错误时在这地方开始的
    .while esi != NULL
        mov eax, (list_node ptr [esi]).data_
        call WriteDec
        call Crlf
        mov esi, (list_node ptr [esi]).next_
    .endw
   
quit:
    call WaitMsg
    invoke ExitProcess, 0
main    endp
end    main

程序报的错误:内存不能read

2011-03-17 20:17
诸葛修勤
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:549
专家分:1955
注 册:2010-10-28
收藏
得分:0 
程序代码:
;#Mode=CON

.386
.model flat, stdcall
option casemap :none

include Irvine32.inc
include windows.inc
include user32.inc
include kernel32.inc
include masm32.inc

includelib user32.lib
includelib kernel32.lib
includelib masm32.lib
include macro.asm


list_node    struct
    data_    DWORD ?
    next_    DWORD ?
list_node    ends
   
;当数据这样定义的时候   在L1~~ja L1 之间循环体 不能够跳出来  看过了是因为count的值引起的但是确实不知道为什么会这样
.data
output_msg    BYTE "输入链表结点的个数: ", 0
input_data    BYTE "输入一个整数: ", 0

hHeap    DWORD ?        ;对分配的句柄
header    DWORD NULL    ;链表的头结点
count    DWORD ?        ;示链表结点数

.code
main    proc
    ;获取堆的句柄
    call GetProcessHeap
    .if eax == NULL
        call WriteWindowsMsg
        jmp quit
    .elseif
        mov hHeap, eax
    .endif
   
    ;从终端接收一个整数表示链表的结点数
    mov edx, offset output_msg
    call WriteString
    call ReadInt
    mov count, eax
L1:
    invoke HeapAlloc, hHeap, HEAP_ZERO_MEMORY, sizeof list_node
    .if eax == NULL
        call WriteWindowsMsg
        jmp quit
    .elseif
        .if header == NULL
            mov header, eax
            mov (list_node ptr [header]).next_, NULL
        .elseif
            mov ebx, header
            mov (list_node ptr[eax]).next_, ebx
            mov header, eax
        .endif
    .endif
    mov edx, offset input_data
    call WriteString
    call ReadInt
    mov (list_node ptr[header]).data_, eax   
    dec count
    cmp count, 0
    ja L1
   
    mov esi, header
    .while esi != NULL
        mov eax, (list_node ptr [esi]).data_
        call WriteDec
        call Crlf
        mov esi, (list_node ptr [esi]).next_
    .endw
   
quit:
    call WaitMsg
    invoke ExitProcess, 0
main    endp
end    main

2011-03-17 20:21
诸葛修勤
Rank: 10Rank: 10Rank: 10
等 级:贵宾
威 望:11
帖 子:549
专家分:1955
注 册:2010-10-28
收藏
得分:0 
程序代码:
;#Mode=CON

.386
.model flat, stdcall
option casemap :none

include Irvine32.inc
include windows.inc
include user32.inc
include kernel32.inc
include masm32.inc

includelib user32.lib
includelib kernel32.lib
includelib masm32.lib
include macro.asm


list_node    struct
    data_    DWORD ?;占四个字节
    next_    DWORD ?
list_node    ends
    

.data
count     DWORD ?        ;示链表结点数
hHeap     DWORD ?        ;对分配的句柄
header    DWORD NULL     ;链表的头结点

output_msg    BYTE "输入链表结点的个数: ", 0
input_data    BYTE "输入一个整数: ", 0



.code
main    proc
    ;获取堆的句柄
    call GetProcessHeap
    .if eax == NULL
        call WriteWindowsMsg
        jmp quit
    .elseif
        mov hHeap, eax
    .endif
   
    ;从终端接收一个整数表示链表的结点数
    mov edx, offset output_msg
    call WriteString
    call ReadInt
    mov count, eax
L1:
    invoke HeapAlloc, hHeap, HEAP_ZERO_MEMORY, sizeof list_node
    .if eax == NULL
        call WriteWindowsMsg
        jmp quit
    .else
        mov ecx, header
        mov (list_node ptr [eax]).next_, ecx
        mov ecx, count
        mov (list_node ptr [eax]).data_, ecx
        mov header, eax
    .endif
   
    dec count
    cmp count, 0
    ja L1
   
    ;从终端中输出链表的结点
    ;
    mov esi, header
    .while esi != NULL
        mov eax, (list_node ptr [esi]).data_
        call WriteDec
        call Crlf
        mov esi, (list_node ptr [esi]).next_
    .endw
   
quit:
    call WaitMsg
    invoke ExitProcess, 0
main    endp
end    main
这样 可以 跑了  可能用了哪些封装的玩意 改动了里面的某些通用寄存器
图片附件: 游客没有浏览图片的权限,请 登录注册
2011-03-18 22:53
快速回复:结构体中怎样定义后继结点(next)
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017370 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved