标签: structure

如何在Java中创建和显示列表?

我必须创建一个列表,比如50个人(在Java中)并显示列表,我真的不知道该怎么做.所以这就是我到目前为止所做的.请更正并完成我的一些代码.

public class Person {

    String name;
    String stuff;
}


public class CreatePerson {



public static void  ang()  {    

    ArrayList<Person> thing=new ArrayList<Person>(); 
    Scanner diskScanner = new Scanner(in);


    for(int i=0; i<50; i++){

        Person pers = new Person();

          out.print("name: ");
      pers.name=diskScanner.nextLine();

      out.print("stuff: ");
      pers.stuff=diskScanner.nextLine();

      thing.add(pers);

          break;

    }
    // Display people  
    for (int i=0; i<50; i++) {
        out.println(??);{
        }

} }}
Run Code Online (Sandbox Code Playgroud)

java structure list arraylist

0
推荐指数
1
解决办法
5834
查看次数

是否有更简单的方法来使用F#可变结构

我现在怎么做真的很奇怪.可悲的是我有很多结构并经常使用它们.

以下是我的表现:

[<type:StructLayout(LayoutKind.Sequential, Pack=1, CharSet=CharSet.Ansi)>]
type OneDevice = {
        mutable id              : UInt16
        mutable typeDev         : byte
        mutable portNum         : byte
        mutable Parity          : byte
        mutable StopBits        : byte
        mutable BaudRate        : byte
        mutable addr1           : byte 
        mutable addr2           : byte 
        mutable useCanal        : byte
        mutable idGroup1        : byte
        mutable idGroup2        : byte 
        mutable idGroup3        : byte
        mutable idGroup4        : byte
        mutable idGroupSos1     : byte 
        mutable idGroupSos2     : byte 
        mutable idGroupSos3     : byte 
        mutable idGroupSos4     : byte 
        mutable idSosReserv     : …
Run Code Online (Sandbox Code Playgroud)

f# structure

0
推荐指数
1
解决办法
156
查看次数

在C中声明结构的新实例

struct xampl {
       int x;
       char y;
};

struct xampl InstaceOfxampl;
struct xampl *PointerToxampl;
struct xampl &new_struct;
Run Code Online (Sandbox Code Playgroud)

我们在第一种情况下创建一个简单的实例,在第二种情况下创建一个指向xampl结构的指针.但是第三个声明是什么意思呢?与代码中的其他两个相比,它的处理方式有何不同?

c c++ pointers structure instance

0
推荐指数
1
解决办法
2722
查看次数

结构初始化为NULL的指针

我对结构中的结构有问题:

typedef struct BrickStruct
{
    int type;
    SDL_Rect Brick_Coordinates;  
    SDL_Surface *Brick_Surface = NULL;  
}BrickStruct; 
Run Code Online (Sandbox Code Playgroud)

我的编译器说关于SDL_Surface结构的行:

error: expected ':', ',', ';', '}' or '__attribute__' before '=' token

但我真的不明白,因为我在我面前听到了关于结构指针的老师的教训: Coordinate *point = NULL;

坐标为两个int内部的结构:int x,y;

有人可以解释一下奇怪的事情吗?

谢谢

c pointers structure

0
推荐指数
1
解决办法
94
查看次数

错误:请求成员不是结构或联合

我的代码遇到了问题.我的程序是一个简化分数的程序.所以我的问题是:

我声明了结构Fraction.然后我在我的main函数中声明了结构Fraction f.

但是当我尝试使用结构分数的任何成员(iefnum,f.den)时,它说它不是结构或联合的成员.我有10个错误,对我的程序都说同样的事情.

错误(逐字):错误:请求成员"num"的东西不是union的结构

#include <stio.h>

struct Fraction{
    int num;
    int den;
    int lownum;//lownum = lowest numerator.
    int lowden;//lowden = lowest denominator
    int error;
};

void enter(struct Fraction *f);
void simplify(struct Fraction *f);
void display(const struct Fraction *f);


int main(void){
    struct Fraction f;

    printf("Fraction Simplifier\n");
    printf("===================\n");

    enter(&f);
    simplify(&f);
    display(&f);
}

void enter(struct Fraction *f){
    printf("Please enter numerator : \n");
    scanf("%d", &f.num);

    printf("please enter denominator : \n");
    scanf("%d", &f.den);

    printf("%d %d", f.num, f.den);
}

void simplify(struct Fraction *f){
    int a; …
Run Code Online (Sandbox Code Playgroud)

c pointers structure

0
推荐指数
1
解决办法
3万
查看次数

返回指向C中结构的指针

该程序返回一个指向结构的指针.
当我打印内容时,名称未正确显示,其他两个变量正在正确打印.
可能是什么问题呢?这是C中的代码

#include<stdio.h>
struct student
    {
        char name[20];
        int marks;
        int rank;
    };
struct student stu;
struct student *create();

void main()
{
    struct student *ptr;
    ptr = create();
    printf("%s\t %d\t %d\t",ptr->name,ptr->marks,ptr->rank);
}

struct student *create()
{
    struct student stu = {"john",98,9};
    struct student *ptrr;
    ptrr = &stu;
    return ptrr;
}
Run Code Online (Sandbox Code Playgroud)

c struct pointers structure char

0
推荐指数
1
解决办法
127
查看次数

qsort不会改变我的数组顺序

我有一个结构数组(员工):

typedef struct Employee{
    char name[MAX_SIZE];
    int salary;
    int experience;
} employee_t;
Run Code Online (Sandbox Code Playgroud)

我想按工资重新排序我的数组,我创建了一个comperator:

int compareEmployeesBySalary(const void* a, const void* b){
        employee_t* one = (employee_t*)a;
        employee_t* two = (employee_t*)b;

        if (one->salary == two->salary)
            return 0;
        else if (one->salary > two->salary)
            return 1;
        else
            return -1;
    }


void main()
{
    int i;

    employee_t** employeeArray = (employee_t**)malloc(sizeof(employee_t*)*5);

    for(i=0 ; i < 2 ; i++)
    {
        employeeArray[i] = (employee_t*)malloc(sizeof(employee_t));
        readEmployee( employeeArray[i] ); //input for 5 employee's
    }

    puts("");
    puts("beforesort\n");
    for(i=0; i <2 ; i++) …
Run Code Online (Sandbox Code Playgroud)

c structure function

0
推荐指数
1
解决办法
128
查看次数

C4473结构分配警告

我目前正在完成一项任务,很好奇编译时这个警告是什么以及如何解决它.它将构建,但是当我调试它将得到一个错误屏幕.以下是出现的警告.

1> c:\ users\cesteves\documents\c programming\inventory\inventory\inventory.cpp(48):警告C4473:'scanf_s':没有为格式字符串传递足够的参数

注意:占位符及其参数需要2个可变参数,但提供了1个

注意:格式字符串'%s'需要缺少的可变参数2注意:此参数用作缓冲区大小

#include "stdafx.h"
#include <stdio.h>

void main()
{
    struct date {
        int day;
        int month;
        int year;
    };

    struct details {
        char name[20];
        int price;
        int code;
        int qty;
        struct date mfg;
    };

    struct details item[50];
    int n, i;

    printf("Enter number of items:");
    scanf_s("%d", &n);

    for (i = 0; i < n; i++) {
        printf("Item name: \n");
        scanf_s("%s", item[i].name);
        printf("Item code: \n");
        scanf_s("%d", &item[i].code);
        printf("Quantity: \n");
        scanf_s("%d", &item[i].qty);
        printf("price: \n");
        scanf_s("%d", &item[i].price);
        printf("Manufacturing date(dd-mm-yyyy): …
Run Code Online (Sandbox Code Playgroud)

c++ structure scanf

0
推荐指数
1
解决办法
4488
查看次数

如果我有一个颜色名称的静态列表及其十六进制等效项,那么使用最快的数据结构是什么?

使用.net核心,所以我无权访问System.Drawing.我有一个865颜色名称及其十六进制等效的列表(0x格式).我永远不需要修改列表,我只需要能够从Either列快速搜索列表(可以搜索名称或十六进制).名称很简单,按字母顺序排列,但Hex是它们的名称.我想让它快速找到对方搜索的方式吗?什么是创建数据结构的最佳方法,以及您将使用哪些搜索方法?

我正在研究http://cc.davelozinski.com/c-sharp/fastest-collection-for-string-lookups

它显示了一些有趣的数据,但它只搜索单个列,所以不是我正在寻找的.如果我只使用颜色名称作为键值,排序列表似乎是要走的路,但是Hex会让我失望.

示例列表:

Air superiority blue    0x72A0C1 
Alabama Crimson     0xA32638 
Alice blue  0xF0F8FF 
Alizarin crimson    0xE32636 
Alloy orange    0xC46210 
Almond  0xEFDECD 
Amaranth    0xE52B50 
Amber   0xFFBF00 
Run Code Online (Sandbox Code Playgroud)

.net c# structure .net-core

0
推荐指数
1
解决办法
964
查看次数

指向结构数组中连续元素的指针不是均匀偏移?

这是一个重复的问题,但无法在任何地方找到正确的解释.

我有以下代码:

#include <stdio.h>
#include <stdlib.h>

typedef struct student_data_boys
{
    int roll_b;
    char name_b[4];
} student_data_boys;

int main()
{
    student_data_boys *ptr;
    int i;
    int num = 5;
    ptr = (student_data_boys *) malloc(num * sizeof(student_data_boys));
    if(ptr == NULL) 
        printf("Can't allocate memory.\n");
        exit(1);
    }
    printf("Allocated memory space size is : %ld bytes.\n",
         (num * sizeof(student_data_boys)));
    for(i=0;i<num;i++) {
        printf("Start address of data1[%d] is : %p.\n", i+1, ptr+i);
    }
    free(ptr);
}
Run Code Online (Sandbox Code Playgroud)

当我递增结构指针时,预期的下一个地址是基地址加上结构块的大小(这里是8),但是当我看到输出时,下一个大小不是预期的.

产出如下:

Allocated memory space is : 40.
Start address of data1[1] is …
Run Code Online (Sandbox Code Playgroud)

c pointers structure pointer-arithmetic

0
推荐指数
1
解决办法
55
查看次数

标签 统计

structure ×10

c ×6

pointers ×5

c++ ×2

.net ×1

.net-core ×1

arraylist ×1

c# ×1

char ×1

f# ×1

function ×1

instance ×1

java ×1

list ×1

pointer-arithmetic ×1

scanf ×1

struct ×1