structure

why use malloc with structure?

廉价感情. 提交于 2019-12-09 17:07:23
问题 Why would I use malloc when same job can be done by without malloc as below.. #include <stdio.h> #include <conio.h> struct node { int data; struct node *l; struct node *r; }; int main(){ //Case 1 struct node n1; n1.data = 99; printf("n1 data is %d\n", n1.data); //Case 2 struct node *n2 = (struct node *) malloc (sizeof(struct node)); n2 -> data = 4444; printf("n2 data is:%d\n",n2 -> data); free(n2); return (0); } I am having hard time to understand how n1 which is not initialized to memory

What is a good data structure to represent an undirected graph?

一曲冷凌霜 提交于 2019-12-09 11:49:50
问题 I need to construct an undirected graph. I don't need it to do anything too fancy, but ideally it would work like this: structure UDG = UndirectedGraph val g = UDG.empty val g = UDG.addEdges(g, n1, [n2, n4, n7]) (* n1 is connected to n2, n4, and n7 *) val g = UDG.addEdge(g, n2, n3) UDG.connected(g, n2) (* returns [n1, n3] *) Is there a good data structure in SML/NJ to model these relationships? Should I just roll my own? Updates I've gone ahead and tried rolling my own, but I get a type

C++学习笔记-5-字符串(string)

纵饮孤独 提交于 2019-12-09 10:31:41
其实,字符串就等同于字符数组。使用字符串时要在头文件中包含<string> string myString="Hello,World!"; cout<<myString<<endl; 等同于 char myS[]="Hello,World!"; 这个输出就要使用循环了。 for(int i=0;i<sizeof(myS)/sizeof(char);i++){ cout<< myS[i];} cout<<endl; 如果用cout<<*myS<<endl;将输出H。全部输出要用: for(int i=0;i<sizeof(myS)/sizeof(char);i++){ cout<<*(myS+i);} cout<<endl; 使用指针: char *ps="Hello,World!"; cout<<ps<<endl; 来源: oschina 链接: https://my.oschina.net/u/185161/blog/32691

C - Find the size of structure

こ雲淡風輕ζ 提交于 2019-12-09 06:32:07
问题 I was asked this as interview question. Couldn't answer. Write a C program to find size of structure without using the sizeof operator. 回答1: struct XYZ{ int x; float y; char z; }; int main(){ struct XYZ arr[2]; int sz = (char*)&arr[1] - (char*)&arr[0]; printf("%d",sz); return 0; } 回答2: Here's another approach. It also isn't completely defined but will still work on most systems. typedef struct{ // stuff } mystruct; int main(){ mystruct x; mystruct *p = &x; int size = (char*)(p + 1) - (char*)p

Convert nested for-loops into single LINQ statement

北战南征 提交于 2019-12-09 05:24:54
问题 can someone please help me turn this nested structure into a single LINQ statement? EventLog[] logs = EventLog.GetEventLogs(); for (int i = 0; i < logs.Length; i++) { if (logs[i].LogDisplayName.Equals("AAA")) { for (int j = 0; j < logs[i].Entries.Count; j++) { if (logs[i].Entries[j].Source.Equals("BBB")) { remoteAccessLogs.Add(logs[i].Entries[j]); } } } } 回答1: Nested loops usually end up with multiple "from" clauses (which are converted into calls to SelectMany by the compiler): var

Looping Forever in a Windows Forms Application

萝らか妹 提交于 2019-12-09 04:57:16
问题 I am using Visual C# sand I'm using a Windows Form rather than a console application. Therefore I'm not working in Main (), but rather in the Form File. I'm also very new to C# so sorry if some of my questions are stupid. What I basically need to do is when my program starts up I need it to keep looping forever. Where would I put this code since I don't have a Main ()? Do I put it in the function that has InitializeComponent() in it? I need the loop to start right after the program starts.

Why OpenCV has no specialize data structure for region?

自古美人都是妖i 提交于 2019-12-09 01:47:54
问题 I have been using MVTec's Halcon Image Processing Library for half a year and OpenCV for 1 year. 1. One thing I found that Halcon much outperforms OpenCV is that OpenCV has no specialize data structure for region. This is lots of waste if I only want to store a small region in a large space. Shouldn't OpenCV have some specialized data structure for region other than Mat Class. 2. Second one, which is the result of the previous one, is that OpenCV is awkward to iterate through regions. Imagine

Default values in a ctypes Structure

两盒软妹~` 提交于 2019-12-08 19:39:46
问题 In a ctypes Structure, is it possible to specify default values? For example, with a regular python function, you can do this: def func(a, b=2): print a + b That would allow for this behaviour: func(1) # prints 3 func(1, 20) # prints 21 func(1, b=50) # prints 51 Is it possible to do this in a ctypes Structure? for example: class Struct(Structure): _fields_ = [("a", c_int), ("b", c_int)] # b default should be 2 def print_values(self): print self.a, self.b struct_instance = Struct(1) struct

c++ structure: repeat set of functions at a certain time rate

谁说我不能喝 提交于 2019-12-08 09:14:40
问题 So I'm stuck with a little c++ program. I use "codeblocks" in a w7 environment. I made a function which shows a ASCII map and a marker. A second function updates the markers position on that map. I would like to know how I could make my main structure so that the marker gets updated and the map showed, and this repeated at a certain time rate. Which functions can I use to make this happen. What strategy should I follow? every x times/second DO { showmap(); updatePosition();} I am a c++

How to Store and Fetch Json Model data to Coredata in Swift

為{幸葍}努か 提交于 2019-12-08 07:44:31
问题 I have used coredata long back. But, I know basics of coredata for storing data and fetching. But, Presently I am working with Swift language. I have local json file and I am doing parsing that by decoder and displaying that data in tableview. let path = Bundle.main.path(forResource: "file", ofType: "json") do { let data = try Data(contentsOf: URL(fileURLWithPath: path ?? ""), options: .mappedIfSafe) let decoder = JSONDecoder() do { quData = try decoder.decode(quData.self, from: data)