Home > Back-end >  Write programs for the first time reading the sequence table a certain element of memory
Write programs for the first time reading the sequence table a certain element of memory

Time:10-04

Procedure is as follows when 0 1 2 3 4 5 6 7 8 9 run out as a result of the - 858993460 - I checked the is out of memory but why

#include
#include
# define Maxsize 100
using namespace std;
Typedef struct
{
The int data [Maxsize];
Int length;
} Sqlist;
Int Initlist (Sqlist L)
{
L.l ength=0;
return 1;
}
Int Creatlist (Sqlist L)
{
int i;
cout<" Please input: "& lt; for(i=0; i<10; I++)
{
Cin> L.d ata [I];
L.l ength++;
}
return 1;
}
Int Getelem (Sqlist L, int, int & amp; E)
{


E=L.d ata [I - 1);

return 1;
}
Int main ()
{Sqlist s;
Int p=100;
Initlist (s);
Creatlist (s);
Getelem (s, 2, p);
coutsystem("pause");
}

CodePudding user response:

Brother, you this value transfer calls, of course not ok.

The reference or pointer,

CodePudding user response:

Int Initlist (Sqlist L)
Int Creatlist (Sqlist L)
Int Getelem (Sqlist L, int, int & amp; E)
These Sqlist should not be quoted?

CodePudding user response:

Int Initlist (Sqlist & amp; L) {
L.l ength=0;
return 1;
}

Int Creatlist (Sqlist & amp; L) {
int i;
Cout & lt; <"Please enter:" & lt; For (I=0; I & lt; 10; I++) {
Cin & gt;> L.d ata [I];
L.l ength++;
}
return 1;
}

Int Getelem (Sqlist & amp; L, int, int & amp; E) {

E=L.d ata [I - 1);

return 1;
}

CodePudding user response:

The
reference 3 floor CCED136 response:
int Initlist (Sqlist & amp; L) {
L.l ength=0;
return 1;
}

Int Creatlist (Sqlist & amp; L) {
int i;
Cout & lt; <"Please enter:" & lt; For (I=0; I & lt; 10; I++) {
Cin & gt;> L.d ata [I];
L.l ength++;
}
return 1;
}

Int Getelem (Sqlist & amp; L, int, int & amp; E) {

E=L.d ata [I - 1);

return 1;
}

support

CodePudding user response:

Well, I know where there is a problem, thank you!!!!! So the question again if you have a singly linked list
Typedef struct Node
{
The int data;
Node * next;
} Node, * LinkList;
So the list I place to insert a node
Void ListInsert (LinkList & amp; L, int, int) e
{
Int j;
LinkList p, s;
P=L - & gt; Next;
J=1;
While (p& & j{
P=p - & gt; Next;
j++;
}
S=(LinkList) malloc (sizeof (Node));
S - & gt; data=https://bbs.csdn.net/topics/e;
S - & gt; Next=p - & gt; Next;
P - & gt; Next=s;
}
LinkList s; It is not already give s application memory space, why s=(LinkList) malloc (sizeof (Node)); This sentence?

CodePudding user response:

Examples of where did you see? P and s is just a pointer, and not for its initialization instance,

Feel your foundation are a little too poor, it is suggested that see more introductory tutorial class book, in addition, the technology about singly linked lists, baidu will be able to tell you,

CodePudding user response:

I seem to see, I see the words "data structure", is based on difference a bit
Not afraid, afraid not learn
  • Related