-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmentor.cpp
More file actions
45 lines (40 loc) · 799 Bytes
/
mentor.cpp
File metadata and controls
45 lines (40 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
Mentor Graphics interview code
Adding a integer element to an link list, no duplicates and the array is sorted smalled to largest.
This is quick code for an interview with Mentor Graphics, if more time was given i would make classes.
*/
struct node {
int val;
node * next;
}
int main(int argc, char * const argv[]){
node * tempptr = new node;
tempptr ->val = value;
tempptr->next = null;
node * ptr2 = head;
node * ptr = NULL;
if(head == NULL){
head = new node;
head->val = value;
head->next = NULL;
}
else{
while(ptr2 != null)
{
if(ptr2->val >= tempptr->val)
break;
ptr = ptr2;
ptr2 = ptr2->next;
}
if(ptr == null)
{
tempptr->next = head;
head = tempptr;
}
else if(ptr2->val != value)
{
ptr2->next = tempptr;
}
}
return 1;
}