class Sqlist () :
Def _init_ (self, maxsize) :
Self. Curlen=0
The self. The maxsize=10
The self. The listitem=[None] * self. Maxsize
Def the clear (self) :
Self. Curlen=0
Def length (self) :
Return the self. Curlen
Def isempty (self) :
If self. Curlen==0:
Print (' the table is empty)
The else:
Print (' the table is not empty)
Def display (self) :
For I in range (self. Curlen) :
Print (self. Listitem [I], end=' ')
Def get (self, I) :
If i<0 or i> Self. Curlen - 1:
Raise the Exception (' the ith element does not exist ')
Return the self. The listitem [I]
Def indexOf (self, x) :
K=1
For I in range (0, the self. Curlen) :
If the self. The listitem [I]==x:
The return of I
K=0
If k==1:
The return - 1
Def insert (self, j, x) :
If self. Curlen==self. Maxsize:
Raise the Exception (' table is full)
If j<0 or j> Self. Curlen - 1:
Print (' insert position illegally)
For I in range (self) curlen, j - 1) :
Self. Llistitem [I]=self. The listitem] [I - 1
The self. The listitem [I]=x
Self. Curlen +=1
Def remove (self, I) : # average mobile number: n - 1/2, mobile expressions: n - I - 1
If i<0 or i> Self. Curlen - 1:
Raise the Exception (' ')
For j in range (I, self. Curlen - 1) :
The self. The listitem. [I]=self listitem [I + 1]
Self. Curlen -=1
SL=Sqlist (10)
SL. Isempty ()
SL. Insert (0, 2)
SL. Insert (1, 5)
SL. Insert (dec 2)
SL. Insert (3 zhongguo kuangye daxue)
SL. Insert (4, 8)
Print (SL) length (SL))
A=SL. Get (5)
Print (' 5 the position of the element are ', a)
SL. Insert (a, 11)
SL. Remove (16)
SL. The display (SL)
To achieve
At run time in
Hope to have with the teacher to correct it
CodePudding user response:
The class Sqlist () :
Def __init__ (self, maxsize) :
Self. Curlen=0
The self. The maxsize=maxsize
The self. The listitem=[None] * self. Maxsize
Def the clear (self) :
Self. Curlen=0
Def length (self) :
Return the self. Curlen
Def isempty (self) :
If self. Curlen==0:
Print (' the table is empty)
The else:
Print (' the table is not empty)
Def display (self) :
For I in range (self. Curlen) :
Print (self. Listitem [I], end=' ')
Print (')
Def get (self, I) :
If i<0 or i> Self. Curlen:
Raise the Exception (' the ith element does not exist ')
Return the self. The listitem [I]
Def indexOf (self, x) :
K=1
For I in range (0, the self. Curlen) :
If the self. The listitem [I]==x:
The return of I
K=0
If k==1:
The return - 1
Def insert (self, j, x) :
If self. Curlen==self. Maxsize:
Raise the Exception (' table is full)
If j<0 or j> Self. Curlen:
Print (' insert position illegally)
For I in range (self curlen, j - 1) :
The self. The listitem. [I]=self listitem] [I - 1
The self. The listitem [j]=x
Self. Curlen +=1
Def remove (self, I) : # average mobile number: n - 1/2, mobile expressions: n - I - 1
If i<0 or i> Self. Curlen - 1:
Raise the Exception (' ')
For j in range (I, self curlen) :
Self. Listitem [j]=self. The listitem [m + 1]
Self. Curlen -=1
SL=Sqlist (10)
SL. Isempty ()
SL. Insert (0, 2)
SL. Insert (1, 5)
SL. Insert (dec 2)
SL. Insert (3 zhongguo kuangye daxue)
SL. Insert (4, 8)
Print (SL) length ())
A=SL. IndexOf (5)
Print (' 5 the position of the element are ', a)
SL. Insert (a + 1, 11)
B=SL. IndexOf (16)
SL. Remove (b)
SL. The display ()