Sistem dizaynı ilə bağlı müsahibə sualları o qədər açıq ola bilər ki, düzgün hazırlaşmağı bilmək çox çətindir. İndi satın aldıqdan sonra Amazon, Microsoft və Adobe-nin dizayn dövrlərini sındıra bilirəm Bu kitabı. Gündəlik bir yenidən nəzərdən keçirin dizayn sualı və söz verirəm ki, dizayn dövrünü sındıra bilərsiniz.
Mündəricat
Bu alqoritmdə, əlaqəli siyahıya elementləri sıralanmış şəkildə daxil edəcəyik, yəni aşağıdan yuxarıya artan qaydada məlumat dəyərləri.
misal
Alqoritm
1. Baş düyünü boşdursa, məlumatları baş düyününə daxil edin.
2. əks halda, giriş məlumatları başlanğıc düyünündən azdırsa, başlanğıcda düyünü daxil edin
3. giriş məlumatları başlanğıc düyünündən böyükdürsə, yerləşdirmək üçün düzgün mövqe əldə edənə qədər müvəqqəti göstəricini hərəkət etdirin. Müvəqqəti göstəricinin növbəti dəyəri sıfırsa, düyünü sonuna daxil edin.
4. Element hər hansı iki dəyər arasındadırsa, qovluğu əvvəlki düyünə və növbəti düyünə, yəni t-> next = temp-> next və temp-> next = t ilə birləşdirin.
C ++ Proqramı
#include <bits/stdc++.h> using namespace std; struct LL{ int data; LL *next; }; void sortedInsert(struct LL**head , int X) { LL*temp = *head ; LL *t = new LL; //if list is empty if(*head==NULL) { *head = new LL; (*head)->data = X; (*head)->next = NULL; } else { if(X < temp->data) //start node { t = new LL; t->data = X; t->next = *head; *head = t; } else { while(temp->next != NULL and !(X < temp->next->data && X >= temp->data)) //as it is sorted so X must lie between the consecutive values or else at end temp=temp->next; if(temp->next == NULL) //X will go to end { temp->next = new LL; temp = temp->next; temp->data = X; temp->next = NULL; } else //X is inserted in between some nodes in list { t = new LL; t->data = X; t->next = temp->next; //make the new node's next as the next of current node because the 't' node will lie between consecutive nodes temp->next = t; } } } } void display(struct LL**head) { struct LL*temp=*head; while(temp!=NULL) { if(temp->next!=NULL) cout<<temp->data<<" ->"; else cout<<temp->data; temp=temp->next; //move to next node } //O(number of nodes) cout<<endl; } int main() { struct LL *head = NULL; //initial list has no elements cout<<"\nCurrent List is :-\n"; display(&head); sortedInsert(&head,6); cout<<"\nCurrent List is :-\n"; display(&head); sortedInsert(&head,16); cout<<"\nCurrent List is :-\n"; display(&head); sortedInsert(&head,15); cout<<"\nCurrent List is :-\n"; display(&head); sortedInsert(&head,50); cout<<"\nCurrent List is :-\n"; display(&head); sortedInsert(&head,1); cout<<"\nCurrent List is :-\n"; display(&head); sortedInsert(&head,23); cout<<"\nCurrent List is :-\n"; display(&head); return 0; }
