VarObj: Handle link lists.

This commit is contained in:
Ernie Pasveer
2022-08-28 14:03:10 -05:00
parent 572bd18a94
commit b1a076d967
12 changed files with 350 additions and 94 deletions
+81
View File
@@ -0,0 +1,81 @@
"4^done,name="seer4",
numchild="1",
value="{...}",
type="Node",
thread-id="1",
has_more="0""
"4^done,numchild="1",
children=[
child={name="seer4.public",exp="public",numchild="2",value="",thread-id="1"}
],
has_more="0""
"4^done,numchild="2",
children=[
child={name="seer4.public.data",exp="data",numchild="0",value="1",type="int",thread-id="1"},
child={name="seer4.public.next",exp="next",numchild="1",value="0x613c40",type="Node *",thread-id="1"}
],
has_more="0""
"4^done,numchild="1",
children=[
child={name="seer4.public.next.public",exp="public",numchild="2",value="",thread-id="1"}
],
has_more="0""
"4^done,numchild="2",
children=[
child={name="seer4.public.next.public.data",exp="data",numchild="0",value="2",type="int",thread-id="1"},
child={name="seer4.public.next.public.next",exp="next",numchild="1",value="0x613c60",type="Node *",thread-id="1"}
],
has_more="0""
"4^done,numchild="1",
children=[
child={name="seer4.public.next.public.next.public",exp="public",numchild="2",value="",thread-id="1"}
],
has_more="0""
"4^done,numchild="2",
children=[
child={name="seer4.public.next.public.next.public.data",exp="data",numchild="0",value="3",type="int",thread-id="1"},
child={name="seer4.public.next.public.next.public.next",exp="next",numchild="1",value="0x0",type="Node *",thread-id="1"}
],
has_more="0""
"4^done,numchild="1",
children=[
child={name="seer4.public.next.public.next.public.next.public",exp="public",numchild="2",value="",thread-id="1"}
],
has_more="0""
"4^done,numchild="2",
children=[
child={name="seer4.public.next.public.next.public.next.public.data",exp="data",numchild="0",value="",type="int",thread-id="1"},
child={name="seer4.public.next.public.next.public.next.public.next",exp="next",numchild="1",value="",type="Node *",thread-id="1"}
],
has_more="0""
"4^done,numchild="1",
children=[
child={name="seer4.public.next.public.next.public.next.public.next.public",exp="public",numchild="2",value="",thread-id="1"}
],
has_more="0""
"4^done,numchild="2",
children=[
child={name="seer4.public.next.public.next.public.next.public.next.public.data",exp="data",numchild="0",value="",type="int",thread-id="1"},
child={name="seer4.public.next.public.next.public.next.public.next.public.next",exp="next",numchild="1",value="",type="Node *",thread-id="1"}
],
has_more="0""
"4^done,numchild="1",
children=[
child={name="seer4.public.next.public.next.public.next.public.next.public.next.public",exp="public",numchild="2",value="",thread-id="1"}
],
has_more="0""
"4^done,numchild="2",
children=[
child={name="seer4.public.next.public.next.public.next.public.next.public.next.public.data",exp="data",numchild="0",value="",type="int",thread-id="1"},
child={name="seer4.public.next.public.next.public.next.public.next.public.next.public.next",exp="next",numchild="1",value="",type="Node *",thread-id="1"}
],
has_more="0""
"4^done,numchild="1",
children=[
child={name="seer4.public.next.public.next.public.next.public.next.public.next.public.next.public",exp="public",numchild="2",value="",thread-id="1"}
],
has_more="0""
+93 -26
View File
@@ -2,38 +2,105 @@
#include <iostream>
#include <string.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
// https://www.geeksforgeeks.org/linked-list-set-1-introduction/
//
// C program to implement a linked list
//
struct Location {
std::string city;
std::string state;
int zip;
struct Node {
int data;
struct Node* next;
};
struct Person {
std::string name;
int age;
float salary;
struct Location* location;
};
// Driver's code
int main() {
struct Node* head = NULL;
struct Node* second = NULL;
struct Node* third = NULL;
// allocate 3 nodes in the heap
head = (struct Node*)malloc(sizeof(struct Node));
second = (struct Node*)malloc(sizeof(struct Node));
third = (struct Node*)malloc(sizeof(struct Node));
/* Three blocks have been allocated dynamically.
We have pointers to these three blocks as head,
second and third
head second third
| | |
| | |
+---+-----+ +----+----+ +----+----+
| # | # | | # | # | | # | # |
+---+-----+ +----+----+ +----+----+
# represents any random value.
Data is random because we havent assigned
anything yet
*/
head->data = 1; // assign data in first node
head->next = second; // Link first node with
// the second node
/* data has been assigned to the data part of the first
block (block pointed by the head). And next
pointer of first block points to second.
So they both are linked.
head second third
| | |
| | |
+---+---+ +----+----+ +-----+----+
| 1 | o----->| # | # | | # | # |
+---+---+ +----+----+ +-----+----+
*/
// assign data to second node
second->data = 2;
// Link second node with the third node
second->next = third;
/* data has been assigned to the data part of the second
block (block pointed by second). And next
pointer of the second block points to the third
block. So all three blocks are linked.
head second third
| | |
| | |
+---+---+ +---+---+ +----+----+
| 1 | o----->| 2 | o-----> | # | # |
+---+---+ +---+---+ +----+----+
*/
third->data = 3; // assign data to third node
third->next = NULL;
/* data has been assigned to data part of third
block (block pointed by third). And next pointer
of the third block is made NULL to indicate
that the linked list is terminated here.
We have the linked list ready.
head
|
|
+---+---+ +---+---+ +----+------+
| 1 | o----->| 2 | o-----> | 3 | NULL |
+---+---+ +---+---+ +----+------+
int main (int argc, char** argv) {
Person me;
me.name = "Pasveer, Ernie";
me.age = 60;
me.salary = 0.25;
//me.location = (struct Location*)malloc(sizeof(struct Location));
me.location = new Location;
me.location->city = "Houston";
me.location->state = "Texas";
me.location->zip = 77063;
std::cout << "'" << me.name << "', from '" << me.location->city << "', is " << me.age << " years old and makes " << me.salary << " per year." << std::endl;
Note that only head is sufficient to represent
the whole list. We can traverse the complete
list by following next pointers.
*/
return 0;
}