void InsertNth(struct node** headRef, int index,
int data)
{
if (index == 0) Push(headRef, data);
else
{
struct node* current = *headRef;
int i;
for (i=0; i
{
current = current->next;
}
Push(&(current->next), data);
}
}
Python tilida birinchi o’rinda ro’yxat bo’sh yoki bo’sh emasligi, keyin
nolinchi pozitsiyadan element qo’shish bajarilmasligi tekshirilishi kerak. Agar
ikkila shart ham bajarilmasa, u holda kerakli pozitsiyani topish qadamlari
bajariladi va element qo’shiladi:
Listing 13. Pythonda ro’yxatga element qo’shish
def InsertNth(self,i,x):
if (self.first == None):
28
Do'stlaringiz bilan baham: |